The HTML Image Element (
<img>) represents an image to the document.
Browsers do not always display the image referenced by the element. This is the case for non-graphical browsers (including those used by people with vision impairments), or if the user chooses not to display images, or if the browser is unable to display the image because it is invalid or an unsupported type. In these cases, the browser may replace the image with the text defined in this element's alt attribute.
|Permitted content||None, this is a void element|
|Tag omission||Must have a start tag and must not have an end tag.|
|Permitted parent elements||Any element that accepts phrasing content.|
|Normative document||HTML 5, section 4.8.1; HTML 4.01, section 13.2|
Like all other HTML elements, this element supports the global attributes.
alignin , in
- The alignment of the image with respect to its surrounding context.
- This attribute defines the alternative text describing the image. Users will see this displayed if the image URL is wrong, the image is not in one of the supported formats, or until the image is downloaded.
Usage note: Omitting this attribute indicates that the image is a key part of the content, but no textual equivalent is available. Setting this attribute to the empty string indicates that this image is not a key part of the content; non-visual browsers may omit it from the rendering.
borderin , in
- The width of a border around the image.
- This enumerated attribute indicates if the fetching of the related image must be done using CORS or not. CORS-enabled images can be reused in the
<canvas>element without being tainted. The allowed values are:
- A cross-origin request (i.e. with
Origin:HTTP header) is performed. But no credential is sent (i.e. no cookie, no X.509 certificate and no HTTP Basic authentication is sent). If the server does not give credentials to the origin site (by not setting the
Access-Control-Allow-Origin:HTTP header), the image will be tainted and its usage restricted..
- A cross-origin request (i.e. with
Origin:HTTP header) is performed with credential is sent (i.e. a cookie, a certificate and HTTP Basic authentication is performed). If the server does not give credentials to the origin site (through
Access-Control-Allow-Credentials:HTTP header), the image will be tainted and its usage restricted.
Origin:HTTP header), preventing its non-tainted used in
<canvas>elements. If invalid, it is handled as if the enumerated keyword anonymous was used. See CORS settings attributes for additional information.
- The height of the image in CSS pixels, or in pixels or as a percentage.
hspacein , in
- The number of pixels of white space to insert to the left and right of the image.
- This Boolean attribute indicates that the image is part of a server-side map. If so, the precise coordinates of a click are sent to the server.
- The URL of a description of the image to be displayed, which supplements the alt text. In
<a>element to link to the description.
, use a regular
namein , in
- A name for the element. It is supported in only for backward compatibility. Use the id attribute instead.
- Image URL, this attribute is obligatory for the
- The width of the image in pixels or percent.
- The partial URL (starting with '#') of an image map associated with the element.
vspacein , in
- The number of pixels of white space to insert to above and below the image.
Supported image formats
The HTML standard doesn't give a list of image format that must be supported, so each user agent supports a different set of formats. Gecko supports:
Support for the XBM format has been removed in Gecko 1.9.2.
This element implements the
<img src="image.jpg" alt="An awesome image" />
|Feature||Chrome||Firefox (Gecko)||Internet Explorer||Opera||Safari (WebKit)|
|Feature||Android||Firefox Mobile (Gecko)||IE Phone||Opera Mobile||Safari Mobile|