diff options
Diffstat (limited to 'devdocs/html/element%2Fimg.html')
| -rw-r--r-- | devdocs/html/element%2Fimg.html | 529 |
1 files changed, 529 insertions, 0 deletions
diff --git a/devdocs/html/element%2Fimg.html b/devdocs/html/element%2Fimg.html new file mode 100644 index 00000000..4bf14c6b --- /dev/null +++ b/devdocs/html/element%2Fimg.html @@ -0,0 +1,529 @@ +<header><h1><img>: The Image Embed element</h1></header><div class="section-content"><p>The <code><img></code> <a href="../index">HTML</a> element embeds an image into the document.</p></div> +<h2 id="try_it">Try it</h2> +<div class="section-content"> +<iframe class="interactive is-tabbed-standard-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/img.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe> <p>The above example shows usage of the <code><img></code> element:</p> <ul> <li>The <code>src</code> attribute is <strong>required</strong>, and contains the path to the image you want to embed.</li> <li>The <code>alt</code> attribute holds a textual replacement for the image, which is mandatory and <strong>incredibly useful</strong> for accessibility — screen readers read the attribute value out to their users so they know what the image means. Alt text is also displayed on the page if the image can't be loaded for some reason: for example, network errors, content blocking, or linkrot.</li> </ul> <p>There are many other attributes to achieve various purposes:</p> <ul> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy">Referrer</a>/<a href="https://developer.mozilla.org/en-US/docs/Glossary/CORS">CORS</a> control for security and privacy: see <a href="#crossorigin"><code>crossorigin</code></a> and <a href="#referrerpolicy"><code>referrerpolicy</code></a>.</li> <li>Use both <a href="#width"><code>width</code></a> and <a href="#height"><code>height</code></a> to set the intrinsic size of the image, allowing it to take up space before it loads, to mitigate content layout shifts.</li> <li>Responsive image hints with <a href="#sizes"><code>sizes</code></a> and <a href="#srcset"><code>srcset</code></a> (see also the <a href="picture"><code><picture></code></a> element and our <a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images">Responsive images</a> tutorial).</li> </ul> +</div> +<h2 id="supported_image_formats">Supported image formats</h2> +<div class="section-content"> +<p>The HTML standard doesn't list what image formats to support, so <a href="https://developer.mozilla.org/en-US/docs/Glossary/User_agent">user agents</a> may support different formats.</p> <div class="notecard note" id="sect1"> <p> <strong>Note:</strong> The <a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types">Image file type and format guide</a> provides comprehensive information about image formats and their web browser support. This section is just a summary! </p> </div> <p>The image file formats that are most commonly used on the web are:</p> <ul> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#apng_animated_portable_network_graphics">APNG (Animated Portable Network Graphics)</a> — Good choice for lossless animation sequences (GIF is less performant)</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#avif_image">AVIF (AV1 Image File Format)</a> — Good choice for both images and animated images due to high performance.</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#gif_graphics_interchange_format">GIF (Graphics Interchange Format)</a> — Good choice for <em>simple</em> images and animations.</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#jpeg_joint_photographic_experts_group_image">JPEG (Joint Photographic Expert Group image)</a> — Good choice for lossy compression of still images (currently the most popular).</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#png_portable_network_graphics">PNG (Portable Network Graphics)</a> — Good choice for lossless compression of still images (slightly better quality than JPEG).</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#svg_scalable_vector_graphics">SVG (Scalable Vector Graphics)</a> — Vector image format. Use for images that must be drawn accurately at different sizes.</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image">WebP (Web Picture format)</a> — Excellent choice for both images and animated images</li> </ul> <p>Formats like <a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#webp_image">WebP</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#avif_image">AVIF</a> are recommended as they perform much better than PNG, JPEG, GIF for both still and animated images. WebP is widely supported while AVIF lacks support in Edge.</p> <p>SVG remains the recommended format for images that must be drawn accurately at different sizes.</p> +</div> +<h2 id="image_loading_errors">Image loading errors</h2> +<div class="section-content"> +<p>If an error occurs while loading or rendering an image, and an <code>onerror</code> event handler has been set for the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/error_event"><code>error</code></a> event, that event handler will get called. This can happen in several situations, including:</p> <ul> <li>The <code>src</code> attribute is empty (<code>""</code>) or <code>null</code>.</li> <li>The <code>src</code> <a href="https://developer.mozilla.org/en-US/docs/Glossary/URL">URL</a> is the same as the URL of the page the user is currently on.</li> <li>The image is corrupted in some way that prevents it from being loaded.</li> <li>The image's metadata is corrupted in such a way that it's impossible to retrieve its dimensions, and no dimensions were specified in the <code><img></code> element's attributes.</li> <li>The image is in a format not supported by the <a href="https://developer.mozilla.org/en-US/docs/Glossary/User_agent">user agent</a>.</li> </ul> +</div> +<h2 id="attributes">Attributes</h2> +<div class="section-content"> +<p>This element includes the <a href="../global_attributes">global attributes</a>.</p> <dl> <dt id="sect2"><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#usage_notes"><code>alt</code></a></dt> <dd> <p>Defines text that can replace the image in the page.</p> <div class="notecard note" id="sect3"> <p><strong>Note:</strong> Browsers do not always display images. There are a number of situations in which a browser might not display images, such as:</p> <ul> <li>Non-visual browsers (such as those used by people with visual impairments)</li> <li>The user chooses not to display images (saving bandwidth, privacy reasons)</li> <li>The image is invalid or an <a href="#supported_image_formats">unsupported type</a> +</li> </ul> <p>In these cases, the browser may replace the image with the text in the element's <code>alt</code> attribute. For these reasons and others, provide a useful value for <code>alt</code> whenever possible.</p> </div> <p>Setting this attribute to an empty string (<code>alt=""</code>) indicates that this image is <em>not</em> a key part of the content (it's decoration or a tracking pixel), and that non-visual browsers may omit it from <a href="https://developer.mozilla.org/en-US/docs/Glossary/Rendering_engine">rendering</a>. Visual browsers will also hide the broken image icon if the <code>alt</code> attribute is empty and the image failed to display.</p> <p>This attribute is also used when copying and pasting the image to text, or saving a linked image to a bookmark.</p> </dd> <dt id="crossorigin"><a href="#crossorigin"><code>crossorigin</code></a></dt> <dd> <p>Indicates if the fetching of the image must be done using a <a href="https://developer.mozilla.org/en-US/docs/Glossary/CORS">CORS</a> request. Image data from a <a href="../cors_enabled_image">CORS-enabled image</a> returned from a CORS request can be reused in the <a href="canvas"><code><canvas></code></a> element without being marked "<a href="../cors_enabled_image#what_is_a_tainted_canvas">tainted</a>".</p> <p>If the <code>crossorigin</code> attribute is <em>not</em> specified, then a non-CORS request is sent (without the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin"><code>Origin</code></a> request header), and the browser marks the image as tainted and restricts access to its image data, preventing its usage in <a href="canvas"><code><canvas></code></a> elements.</p> <p>If the <code>crossorigin</code> attribute <em>is</em> specified, then a CORS request is sent (with the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin"><code>Origin</code></a> request header); but if the server does not opt into allowing cross-origin access to the image data by the origin site (by not sending any <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin"><code>Access-Control-Allow-Origin</code></a> response header, or by not including the site's origin in any <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin"><code>Access-Control-Allow-Origin</code></a> response header it does send), then the browser blocks the image from loading, and logs a CORS error to the devtools console.</p> <p>Allowed values:</p> <dl> <dt id="anonymous"><a href="#anonymous"><code>anonymous</code></a></dt> <dd> <p>A CORS request is sent with credentials omitted (that is, no <a href="https://developer.mozilla.org/en-US/docs/Glossary/Cookie">cookies</a>, <a href="https://datatracker.ietf.org/doc/html/rfc5280" target="_blank">X.509 certificates</a>, or <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization"><code>Authorization</code></a> request header).</p> </dd> <dt id="use-credentials"><a href="#use-credentials"><code>use-credentials</code></a></dt> <dd> <p>The CORS request is sent with any credentials included (that is, cookies, X.509 certificates, and the <code>Authorization</code> request header). If the server does not opt into sharing credentials with the origin site (by sending back the <code>Access-Control-Allow-Credentials: true</code> response header), then the browser marks the image as tainted and restricts access to its image data.</p> </dd> </dl> <p>If the attribute has an invalid value, browsers handle it as if the <code>anonymous</code> value was used. See <a href="../attributes/crossorigin">CORS settings attributes</a> for additional information.</p> </dd> <dt id="decoding"><a href="#decoding"><code>decoding</code></a></dt> <dd> <p>This attribute provides a hint to the browser as to whether it should perform image decoding along with rendering the other DOM content in a single presentation step that looks more "correct" (<code>sync</code>), or render and present the other DOM content first and then decode the image and present it later (<code>async</code>). In practice, <code>async</code> means that the next paint does not wait for the image to decode.</p> <p>It is often difficult to perceive any noticeable effect when using <code>decoding</code> on static <code><img></code> elements. They'll likely be initially rendered as empty images while the image files are fetched (either from the network or from the cache) and then handled independently anyway, so the "syncing" of content updates is less apparent. However, the blocking of rendering while decoding happens, while often quite small, <em>can</em> be measured — even if it is difficult to observe with the human eye. See <a href="https://www.tunetheweb.com/blog/what-does-the-image-decoding-attribute-actually-do/" target="_blank">What does the image decoding attribute actually do?</a> for a more detailed analysis (tunetheweb.com, 2023).</p> <p>Using different <code>decoding</code> types can result in more noticeable differences when dynamically inserting <code><img></code> elements into the DOM via JavaScript — see <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding"><code>HTMLImageElement.decoding</code></a> for more details.</p> <p>Allowed values:</p> <dl> <dt id="sync"><a href="#sync"><code>sync</code></a></dt> <dd> <p>Decode the image synchronously along with rendering the other DOM content, and present everything together.</p> </dd> <dt id="async"><a href="#async"><code>async</code></a></dt> <dd> <p>Decode the image asynchronously, after rendering and presenting the other DOM content.</p> </dd> <dt id="auto"><a href="#auto"><code>auto</code></a></dt> <dd> <p>No preference for the decoding mode; the browser decides what is best for the user. This is the default value.</p> </dd> </dl> </dd> <dt id="elementtiming"><a href="#elementtiming"><code>elementtiming</code></a></dt> <dd> <p>Marks the image for observation by the <a href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceElementTiming"><code>PerformanceElementTiming</code></a> API. The value given becomes an identifier for the observed image element. See also the <a href="../attributes/elementtiming"><code>elementtiming</code></a> attribute page.</p> </dd> <dt id="fetchpriority"> +<a href="#fetchpriority"><code>fetchpriority</code></a> <abbr class="icon icon-experimental" title="Experimental. Expect behavior to change in the future."> <span class="visually-hidden">Experimental</span> </abbr> +</dt> <dd> <p>Provides a hint of the relative priority to use when fetching the image. Allowed values:</p> <dl> <dt id="high"><a href="#high"><code>high</code></a></dt> <dd> <p>Signals a high-priority fetch relative to other images.</p> </dd> <dt id="low"><a href="#low"><code>low</code></a></dt> <dd> <p>Signals a low-priority fetch relative to other images.</p> </dd> <dt id="auto_2"><a href="#auto_2"><code>auto</code></a></dt> <dd> <p>Default: Signals automatic determination of fetch priority relative to other images.</p> </dd> </dl> </dd> <dt id="height"><a href="#height"><code>height</code></a></dt> <dd> <p>The intrinsic height of the image, in pixels. Must be an integer without a unit.</p> <div class="notecard note" id="sect4"> <p><strong>Note:</strong> Including <code>height</code> and <a href="#width"><code>width</code></a> enables the aspect ratio of the image to be calculated by the browser prior to the image being loaded. This aspect ratio is used to reserve the space needed to display the image, reducing or even preventing a layout shift when the image is downloaded and painted to the screen. Reducing layout shift is a major component of good user experience and web performance.</p> </div> </dd> <dt id="ismap"><a href="#ismap"><code>ismap</code></a></dt> <dd> <p>This Boolean attribute indicates that the image is part of a <a href="https://en.wikipedia.org/wiki/Image_map#Server-side" target="_blank">server-side map</a>. If so, the coordinates where the user clicked on the image are sent to the server.</p> <div class="notecard note" id="sect5"> <p><strong>Note:</strong> This attribute is allowed only if the <code><img></code> element is a descendant of an <a href="a"><code><a></code></a> element with a valid <a href="a#href"><code>href</code></a> attribute. This gives users without pointing devices a fallback destination.</p> </div> </dd> <dt id="loading"><a href="#loading"><code>loading</code></a></dt> <dd> <p>Indicates how the browser should load the image:</p> <dl> <dt id="eager"><a href="#eager"><code>eager</code></a></dt> <dd> <p>Loads the image immediately, regardless of whether or not the image is currently within the visible viewport (this is the default value).</p> </dd> <dt id="lazy"><a href="#lazy"><code>lazy</code></a></dt> <dd> <p>Defers loading the image until it reaches a calculated distance from the viewport, as defined by the browser. The intent is to avoid the network and storage bandwidth needed to handle the image until it's reasonably certain that it will be needed. This generally improves the performance of the content in most typical use cases.</p> </dd> </dl> <div class="notecard note" id="sect6"> <p><strong>Note:</strong> Loading is only deferred when JavaScript is enabled. This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user's approximate scroll position throughout a session, by strategically placing images in a page's markup such that a server can track how many images are requested and when.</p> </div> </dd> <dt id="referrerpolicy"><a href="#referrerpolicy"><code>referrerpolicy</code></a></dt> <dd> <p>A string indicating which referrer to use when fetching the resource:</p> <ul> <li> +<code>no-referrer</code>: The <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer"><code>Referer</code></a> header will not be sent.</li> <li> +<code>no-referrer-when-downgrade</code>: The <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer"><code>Referer</code></a> header will not be sent to <a href="https://developer.mozilla.org/en-US/docs/Glossary/Origin">origin</a>s without <a href="https://developer.mozilla.org/en-US/docs/Glossary/TLS">TLS</a> (<a href="https://developer.mozilla.org/en-US/docs/Glossary/HTTPS">HTTPS</a>).</li> <li> +<code>origin</code>: The sent referrer will be limited to the origin of the referring page: its <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL">scheme</a>, <a href="https://developer.mozilla.org/en-US/docs/Glossary/Host">host</a>, and <a href="https://developer.mozilla.org/en-US/docs/Glossary/Port">port</a>.</li> <li> +<code>origin-when-cross-origin</code>: The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.</li> <li> +<code>same-origin</code>: A referrer will be sent for <a href="https://developer.mozilla.org/en-US/docs/Glossary/Same-origin_policy">same origin</a>, but cross-origin requests will contain no referrer information.</li> <li> +<code>strict-origin</code>: Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don't send it to a less secure destination (HTTPS→HTTP).</li> <li> +<code>strict-origin-when-cross-origin</code> (default): Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).</li> <li> +<code>unsafe-url</code>: The referrer will include the origin <em>and</em> the path (but not the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hash">fragment</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/password">password</a>, or <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/username">username</a>). <strong>This value is unsafe</strong>, because it leaks origins and paths from TLS-protected resources to insecure origins.</li> </ul> </dd> <dt id="sizes"><a href="#sizes"><code>sizes</code></a></dt> <dd> <p>One or more strings separated by commas, indicating a set of source sizes. Each source size consists of:</p> <ol> <li>A <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_media_queries/Using_media_queries#syntax">media condition</a>. This must be omitted for the last item in the list.</li> <li>A source size value.</li> </ol> <p>Media Conditions describe properties of the <em>viewport</em>, not of the <em>image</em>. For example, <code>(max-height: 500px) 1000px</code> proposes to use a source of 1000px width, if the <em>viewport</em> is not higher than 500px.</p> <p>Source size values specify the intended display size of the image. <a href="https://developer.mozilla.org/en-US/docs/Glossary/User_agent">User agents</a> use the current source size to select one of the sources supplied by the <code>srcset</code> attribute, when those sources are described using width (<code>w</code>) descriptors. The selected source size affects the <a href="https://developer.mozilla.org/en-US/docs/Glossary/Intrinsic_Size">intrinsic size</a> of the image (the image's display size if no <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSS">CSS</a> styling is applied). If the <code>srcset</code> attribute is absent, or contains no values with a width descriptor, then the <code>sizes</code> attribute has no effect.</p> </dd> <dt id="src"><a href="#src"><code>src</code></a></dt> <dd> <p>The image <a href="https://developer.mozilla.org/en-US/docs/Glossary/URL">URL</a>. Mandatory for the <code><img></code> element. On <a href="https://developer.mozilla.org/en-US/docs/Glossary/Browser">browsers</a> supporting <code>srcset</code>, <code>src</code> is treated like a candidate image with a pixel density descriptor <code>1x</code>, unless an image with this pixel density descriptor is already defined in <code>srcset</code>, or unless <code>srcset</code> contains <code>w</code> descriptors.</p> </dd> <dt id="srcset"><a href="#srcset"><code>srcset</code></a></dt> <dd> <p>One or more strings separated by commas, indicating possible image sources for the <a href="https://developer.mozilla.org/en-US/docs/Glossary/User_agent">user agent</a> to use. Each string is composed of:</p> <ol> <li>A <a href="https://developer.mozilla.org/en-US/docs/Glossary/URL">URL</a> to an image</li> <li>Optionally, whitespace followed by one of: <ul> <li>A width descriptor (a positive integer directly followed by <code>w</code>). The width descriptor is divided by the source size given in the <code>sizes</code> attribute to calculate the effective pixel density.</li> <li>A pixel density descriptor (a positive floating point number directly followed by <code>x</code>).</li> </ul> </li> </ol> <p>If no descriptor is specified, the source is assigned the default descriptor of <code>1x</code>.</p> <p>It is incorrect to mix width descriptors and pixel density descriptors in the same <code>srcset</code> attribute. Duplicate descriptors (for instance, two sources in the same <code>srcset</code> which are both described with <code>2x</code>) are also invalid.</p> <p>If the <code>srcset</code> attribute uses width descriptors, the <code>sizes</code> attribute must also be present, or the <code>srcset</code> itself will be ignored.</p> <p>The user agent selects any of the available sources at its discretion. This provides them with significant leeway to tailor their selection based on things like user preferences or <a href="https://developer.mozilla.org/en-US/docs/Glossary/Bandwidth">bandwidth</a> conditions. See our <a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images">Responsive images</a> tutorial for an example.</p> </dd> <dt id="width"><a href="#width"><code>width</code></a></dt> <dd> <p>The intrinsic width of the image in pixels. Must be an integer without a unit.</p> </dd> <dt id="usemap"><a href="#usemap"><code>usemap</code></a></dt> <dd> <p>The partial <a href="https://developer.mozilla.org/en-US/docs/Glossary/URL">URL</a> (starting with <code>#</code>) of an <a href="map">image map</a> associated with the element.</p> <div class="notecard note" id="sect7"> <p><strong>Note:</strong> You cannot use this attribute if the <code><img></code> element is inside an <a href="a"><code><a></code></a> or <a href="button"><code><button></code></a> element.</p> </div> </dd> </dl> +</div> +<h3 id="deprecated_attributes">Deprecated attributes</h3> +<div class="section-content"><dl> <dt id="align"> +<a href="#align"><code>align</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> +</dt> <dd> <p>Aligns the image with its surrounding context. Use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/float"><code>float</code></a> and/or <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align"><code>vertical-align</code></a> <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSS">CSS</a> properties instead of this attribute. Allowed values:</p> <dl> <dt id="top"><a href="#top"><code>top</code></a></dt> <dd> <p>Equivalent to <code>vertical-align: top</code> or <code>vertical-align: text-top</code></p> </dd> <dt id="middle"><a href="#middle"><code>middle</code></a></dt> <dd> <p>Equivalent to <code>vertical-align: -moz-middle-with-baseline</code></p> </dd> <dt id="bottom"><a href="#bottom"><code>bottom</code></a></dt> <dd> <p>The default, equivalent to <code>vertical-align: unset</code> or <code>vertical-align: initial</code></p> </dd> <dt id="left"><a href="#left"><code>left</code></a></dt> <dd> <p>Equivalent to <code>float: left</code></p> </dd> <dt id="right"><a href="#right"><code>right</code></a></dt> <dd> <p>Equivalent to <code>float: right</code></p> </dd> </dl> </dd> <dt id="border"> +<a href="#border"><code>border</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> +</dt> <dd> <p>The width of a border around the image. Use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/border"><code>border</code></a> <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSS">CSS</a> property instead.</p> </dd> <dt id="hspace"> +<a href="#hspace"><code>hspace</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> +</dt> <dd> <p>The number of pixels of white space on the left and right of the image. Use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin"><code>margin</code></a> CSS property instead.</p> </dd> <dt id="longdesc"> +<a href="#longdesc"><code>longdesc</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> +</dt> <dd> <p>A link to a more detailed description of the image. Possible values are a <a href="https://developer.mozilla.org/en-US/docs/Glossary/URL">URL</a> or an element <a href="../global_attributes#id"><code>id</code></a>.</p> <div class="notecard note" id="sect8"> <p><strong>Note:</strong> This attribute is mentioned in the latest <a href="https://developer.mozilla.org/en-US/docs/Glossary/W3C">W3C</a> version, <a href="https://html.spec.whatwg.org/multipage/obsolete.html#element-attrdef-img-longdesc" target="_blank">HTML 5.2</a>, but has been removed from the <a href="https://developer.mozilla.org/en-US/docs/Glossary/WHATWG">WHATWG</a>'s <a href="https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element" target="_blank">HTML Living Standard</a>. It has an uncertain future; authors should use a <a href="https://developer.mozilla.org/en-US/docs/Glossary/WAI">WAI</a>-<a href="https://developer.mozilla.org/en-US/docs/Glossary/ARIA">ARIA</a> alternative such as <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-describedby" target="_blank"><code>aria-describedby</code></a> or <a href="https://www.w3.org/TR/wai-aria-1.1/#aria-details" target="_blank"><code>aria-details</code></a>.</p> </div> </dd> <dt id="name"> +<a href="#name"><code>name</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> +</dt> <dd> <p>A name for the element. Use the <a href="../global_attributes#id"><code>id</code></a> attribute instead.</p> </dd> <dt id="vspace"> +<a href="#vspace"><code>vspace</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> +</dt> <dd> <p>The number of pixels of white space above and below the image. Use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin"><code>margin</code></a> CSS property instead.</p> </dd> </dl></div> +<h2 id="styling_with_css">Styling with CSS</h2> +<div class="section-content"> +<p><code><img></code> is a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Replaced_element">replaced element</a>; it has a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/display"><code>display</code></a> value of <code>inline</code> by default, but its default dimensions are defined by the embedded image's intrinsic values, like it were <code>inline-block</code>. You can set properties like <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/border"><code>border</code></a>/<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius"><code>border-radius</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/padding"><code>padding</code></a>/<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin"><code>margin</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/width"><code>width</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/height"><code>height</code></a>, etc. on an image.</p> <p><code><img></code> has no baseline, so when images are used in an inline formatting context with <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align"><code>vertical-align</code></a><code>: baseline</code>, the bottom of the image will be placed on the text baseline.</p> <p>You can use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-position"><code>object-position</code></a> property to position the image within the element's box, and the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit"><code>object-fit</code></a> property to adjust the sizing of the image within the box (for example, whether the image should fit the box or fill it even if clipping is required).</p> <p>Depending on its type, an image may have an intrinsic width and height. For some image types, however, intrinsic dimensions are unnecessary. <a href="https://developer.mozilla.org/en-US/docs/Glossary/SVG">SVG</a> images, for instance, have no intrinsic dimensions if their root <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg"><code><svg></code></a> element doesn't have a <code>width</code> or <code>height</code> set on it.</p> +</div> +<h2 id="examples">Examples</h2> + +<h3 id="alternative_text">Alternative text</h3> +<div class="section-content"> +<p>The following example embeds an image into the page and includes alternative text for accessibility.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="owjcNOrN219yg3iKRcKaaPmOYfXnrejrsxOKzbGsZDc=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>favicon144.png<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>MDN<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> +<div class="code-example" id="sect9"> + +<iframe class="sample-code-frame" title="Alternative text sample" id="frame_alternative_text" width="100%" height="160" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/runner.html?id=alternative_text" loading="lazy"></iframe> +</div> +</div> +<h3 id="image_link">Image link</h3> +<div class="section-content"> +<p>This example builds upon the previous one, showing how to turn the image into a link. To do so, nest the <code><img></code> tag inside the <a href="a"><code><a></code></a>. You should make the alternative text describe the resource the link is pointing to, as if you were using a text link instead.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="7CryCKtQg/khYqUXGCooYLwWrqQlfE0eBB4K7IyHCxA=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>a</span> <span class="token attr-name">href</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>https://developer.mozilla.org<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> + <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>favicon144.png<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>Visit the MDN site<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>a</span><span class="token punctuation">></span></span> +</pre> +</div> +<div class="code-example" id="sect10"> + +<iframe class="sample-code-frame" title="Image link sample" id="frame_image_link" width="100%" height="160" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/runner.html?id=image_link" loading="lazy"></iframe> +</div> +</div> +<h3 id="using_the_srcset_attribute">Using the srcset attribute</h3> +<div class="section-content"> +<p>In this example we include a <code>srcset</code> attribute with a reference to a high-resolution version of the logo; this will be loaded instead of the <code>src</code> image on high-resolution devices. The image referenced in the <code>src</code> attribute is counted as a <code>1x</code> candidate in <a href="https://developer.mozilla.org/en-US/docs/Glossary/User_agent">user agents</a> that support <code>srcset</code>.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="YrM9b58B66yBkbVB51Sn8w3ehpEAhU4SRmoKpYVATlU=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>favicon72.png<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>MDN<span class="token punctuation">"</span></span> <span class="token attr-name">srcset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>favicon144.png 2x<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> +<div class="code-example" id="sect11"> + +<iframe class="sample-code-frame" title="Using the srcset attribute sample" id="frame_using_the_srcset_attribute" width="100%" height="160" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/runner.html?id=using_the_srcset_attribute" loading="lazy"></iframe> +</div> +</div> +<h3 id="using_the_srcset_and_sizes_attributes">Using the srcset and sizes attributes</h3> +<div class="section-content"> +<p>The <code>src</code> attribute is ignored in <a href="https://developer.mozilla.org/en-US/docs/Glossary/User_agent">user agents</a> that support <code>srcset</code> when <code>w</code> descriptors are included. When the <code>(max-width: 600px)</code> media condition matches, the 200 pixel-wide image will load (it is the one that matches <code>200px</code> most closely), otherwise the other image will load.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="alqbLOcNsLV6IzZONHZ8iUn2JpGmb0xFTz3mJ41ADlo=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> + <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>clock-demo-200px.png<span class="token punctuation">"</span></span> + <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>The time is 12:45.<span class="token punctuation">"</span></span> + <span class="token attr-name">srcset</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>clock-demo-200px.png 200w, clock-demo-400px.png 400w<span class="token punctuation">"</span></span> + <span class="token attr-name">sizes</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>(max-width: 600px) 200px, 50vw<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> +<div class="code-example" id="sect12"> + +<iframe class="sample-code-frame" title="Using the srcset and sizes attributes sample" id="frame_using_the_srcset_and_sizes_attributes" width="100%" height="350" src="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/runner.html?id=using_the_srcset_and_sizes_attributes" loading="lazy"></iframe> +</div> <div class="notecard note" id="sect13"> <p><strong>Note:</strong> To see the resizing in action, <a href="https://live.mdnplay.dev/en-US/docs/Web/HTML/Element/img/_sample_.Using_the_srcset_and_sizes_attributes.html?id=Using_the_srcset_and_sizes_attributes&amp;url=%2Fen-US%2Fdocs%2FWeb%2FHTML%2FElement%2Fimg" target="_blank">view the example on a separate page</a>, so you can actually resize the content area.</p> </div> +</div> +<h2 id="security_and_privacy_concerns">Security and privacy concerns</h2> +<div class="section-content"><p>Although <code><img></code> elements have innocent uses, they can have undesirable consequences for user security and privacy. See <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Referer_header:_privacy_and_security_concerns">Referer header: privacy and security concerns</a> for more information and mitigations.</p></div> +<h2 id="accessibility_concerns">Accessibility concerns</h2> + +<h3 id="authoring_meaningful_alternate_descriptions">Authoring meaningful alternate descriptions</h3> +<div class="section-content"> +<p>An <code>alt</code> attribute's value should provide a clear and concise text replacement for the image's content. It should not describe the presence of the image itself or the file name of the image. If the <code>alt</code> attribute is purposefully left off because the image has no textual equivalent, consider alternate methods to present what the image is trying to communicate.</p> <h4 id="dont">Don't</h4> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="oQYtLZv6V54aLNmW+iXYmq5sNs2oiWpJjE7JTHr+kts=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>image<span class="token punctuation">"</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>penguin.jpg<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> <h4 id="do">Do</h4> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="yt9ke/ua4qnJKXkKDzyi9acDW4o5pVfRkqbe02GuaUA=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>A Rockhopper Penguin is standing on a beach.<span class="token punctuation">"</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>penguin.jpg<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> <p>When an <code>alt</code> attribute is not present on an image, some screen readers may announce the image's file name instead. This can be a confusing experience if the file name isn't representative of the image's contents.</p> <ul> <li><a href="https://www.w3.org/WAI/tutorials/images/decision-tree/" target="_blank">An alt Decision Tree • Images • WAI Web Accessibility Tutorials</a></li> <li><a href="https://axesslab.com/alt-texts/" target="_blank">Alt-texts: The Ultimate Guide — Axess Lab</a></li> <li><a href="https://www.deque.com/blog/great-alt-text-introduction/" target="_blank">How to Design Great Alt Text: An Introduction | Deque</a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#guideline_1.1_%E2%80%94_providing_text_alternatives_for_non-text_content">MDN Understanding WCAG, Guideline 1.1 explanations</a></li> <li><a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/text-equiv-all.html" target="_blank">Understanding Success Criterion 1.1.1 | W3C Understanding WCAG 2.0</a></li> </ul> +</div> +<h3 id="identifying_svg_as_an_image">Identifying SVG as an image</h3> +<div class="section-content"> +<p>Due to a <a href="https://webkit.org/b/216364" target="_blank">VoiceOver bug</a>, VoiceOver does not correctly announce SVG images as images. Include <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/img_role"><code>role="img"</code></a> to all <code><img></code> elements with SVG source files to ensure assistive technologies correctly announce the SVG as image content.</p> <div class="code-example"> +<p class="example-header"><span class="language-name">html</span></p> +<pre data-signature="HO1k15q9PuaukCQvSewmT6jm7AqRxgEN6QL23wAB8CM=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>img</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>mdn.svg<span class="token punctuation">"</span></span> <span class="token attr-name">alt</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>MDN<span class="token punctuation">"</span></span> <span class="token attr-name">role</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>img<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span> +</pre> +</div> +</div> +<h3 id="the_title_attribute">The title attribute</h3> +<div class="section-content"> +<p>The <a href="../global_attributes#title"><code>title</code></a> attribute is not an acceptable substitute for the <code>alt</code> attribute. Additionally, avoid duplicating the <code>alt</code> attribute's value in a <code>title</code> attribute declared on the same image. Doing so may cause some screen readers to announce the same text twice, creating a confusing experience.</p> <p>The <code>title</code> attribute should also not be used as supplemental captioning information to accompany an image's <code>alt</code> description. If an image needs a caption, use the <a href="figure"><code>figure</code></a> and <a href="figcaption"><code>figcaption</code></a> elements.</p> <p>The value of the <code>title</code> attribute is usually presented to the user as a tooltip, which appears shortly after the cursor stops moving over the image. While this <em>can</em> provide additional information to the user, you should not assume that the user will ever see it: the user may only have keyboard or touchscreen. If you have information that's particularly important or valuable for the user, present it inline using one of the methods mentioned above instead of using <code>title</code>.</p> <ul> <li><a href="https://www.tpgi.com/using-the-html-title-attribute-updated/" target="_blank">Using the HTML title attribute – updated | The Paciello Group</a></li> </ul> +</div> +<h2 id="technical_summary">Technical summary</h2> +<div class="section-content"><figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td> <a href="../content_categories#flow_content">Flow content</a>, <a href="../content_categories#phrasing_content">phrasing content</a>, <a href="../content_categories#embedded_content">embedded content</a>, <a href="../content_categories#palpable_content">palpable content</a>. If the element has a <code>usemap</code> attribute, it also is a part of the interactive content category. </td> </tr> <tr> <th scope="row">Permitted content</th> <td>None; it is a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Void_element">void element</a>.</td> </tr> <tr> <th scope="row">Tag omission</th> <td>Must have a start tag and must not have an end tag.</td> </tr> <tr> <th scope="row">Permitted parents</th> <td>Any element that accepts embedded content.</td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td> <ul> <li> with non-empty <code>alt</code> attribute or no <code>alt</code> attribute: <code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/img_role"><code>img</code></a></code> </li> <li> with empty <code>alt</code> attribute: <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/presentation_role"><code>presentation</code></a> </li> </ul> </td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td> <ul> <li>with non-empty <code>alt</code> attribute: <ul> <li><code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role">button</a></code></li> <li><code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/checkbox_role">checkbox</a></code></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/link_role"><code>link</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/menuitem_role"><code>menuitem</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/menuitemcheckbox_role"><code>menuitemcheckbox</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/menuitemradio_role"><code>menuitemradio</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/option_role"><code>option</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/progressbar_role"><code>progressbar</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/scrollbar_role"><code>scrollbar</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/separator_role"><code>separator</code></a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/slider_role"><code>slider</code></a></li> <li><code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/switch_role">switch</a></code></li> <li><code><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/tab_role">tab</a></code></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/treeitem_role"><code>treeitem</code></a></li> </ul> </li> <li> with empty <code>alt</code> attribute, <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/none_role"><code>none</code></a> or <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/presentation_role"><code>presentation</code></a> </li> <li>with no <code>alt</code> attribute, no <code>role</code> permitted</li> </ul> </td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement"><code>HTMLImageElement</code></a></td> </tr> </tbody> </table></div></figure></div> +<h2 id="specifications">Specifications</h2> +<div class="_table"><table class="standard-table"> +<thead><tr><th scope="col">Specification</th></tr></thead> +<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element">HTML Standard <br><small># the-img-element</small></a></td></tr></tbody> +</table></div> +<h2 id="browser_compatibility">Browser compatibility</h2> +<div class="_table"><table> +<thead> +<tr id="bct-browser-type"> +<th></th> +<th colspan="6">Desktop</th> +<th colspan="6">Mobile</th> +</tr> +<tr id="bct-browsers"> +<th></th> +<th>Chrome</th> +<th>Edge</th> +<th>Firefox</th> +<th>Internet Explorer</th> +<th>Opera</th> +<th>Safari</th> +<th>WebView Android</th> +<th>Chrome Android</th> +<th>Firefox for Android</th> +<th>Opera Android</th> +<th>Safari on IOS</th> +<th>Samsung Internet</th> +</tr> +</thead> +<tbody> +<tr> +<th><code>img</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>align</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>alt</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>aspect_ratio_computed_from_attributes</code></th> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">71</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">66</td> +<td class="bc-supports-yes">15<details><summary>14–15</summary>Safari doesn't preserve space for images without a valid <code>src</code>, which may disrupt layouts that rely on lazy loading (see <a href="https://webkit.org/b/224197">bug 224197</a>).</details> +</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">57</td> +<td class="bc-supports-yes">15<details><summary>14–15</summary>Safari doesn't preserve space for images without a valid <code>src</code>, which may disrupt layouts that rely on lazy loading (see <a href="https://webkit.org/b/224197">bug 224197</a>).</details> +</td> +<td class="bc-supports-yes">12.0</td> +</tr> +<tr> +<th><code>attributionsrc</code></th> +<td class="bc-supports-yes">117</td> +<td class="bc-supports-yes">117</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">103</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">117</td> +<td class="bc-supports-yes">117</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-no">No</td> +</tr> +<tr> +<th><code>border</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>crossorigin</code></th> +<td class="bc-supports-yes">13</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">8</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">6</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">8</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">6</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>decoding</code></th> +<td class="bc-supports-yes">65</td> +<td class="bc-supports-yes">≤79</td> +<td class="bc-supports-yes">63</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">52</td> +<td class="bc-supports-yes">11.1</td> +<td class="bc-supports-yes">65</td> +<td class="bc-supports-yes">65</td> +<td class="bc-supports-yes">63</td> +<td class="bc-supports-yes">47</td> +<td class="bc-supports-yes">11.3</td> +<td class="bc-supports-yes">9.0</td> +</tr> +<tr> +<th><code>fetchpriority</code></th> +<td class="bc-supports-yes">101</td> +<td class="bc-supports-yes">101</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">preview</td> +<td class="bc-supports-yes">101</td> +<td class="bc-supports-yes">101</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">70</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">19.0</td> +</tr> +<tr> +<th><code>height</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>hspace</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>ismap</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>loading</code></th> +<td class="bc-supports-yes">77</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">75</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">64</td> +<td class="bc-supports-yes">15.4</td> +<td class="bc-supports-yes">77</td> +<td class="bc-supports-yes">77</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">55</td> +<td class="bc-supports-yes">15.4</td> +<td class="bc-supports-yes">12.0</td> +</tr> +<tr> +<th><code>longdesc</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>name</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>onerror</code></th> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">≤79</td> +<td class="bc-supports-yes">51</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">51</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">Yes</td> +</tr> +<tr> +<th><code>referrerpolicy</code></th> +<td class="bc-supports-yes">51</td> +<td class="bc-supports-yes">79</td> +<td class="bc-supports-yes">50</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">51</td> +<td class="bc-supports-yes">51</td> +<td class="bc-supports-yes">50</td> +<td class="bc-supports-yes">41</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">7.2</td> +</tr> +<tr> +<th><code>sizes</code></th> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">25</td> +<td class="bc-supports-yes">9.1</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">25</td> +<td class="bc-supports-yes">9.3</td> +<td class="bc-supports-yes">3.0</td> +</tr> +<tr> +<th><code>src</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>srcset</code></th> +<td class="bc-supports-yes">34</td> +<td class="bc-supports-yes">≤18</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-no">No</td> +<td class="bc-supports-yes">21</td> +<td class="bc-supports-yes">8</td> +<td class="bc-supports-yes">37</td> +<td class="bc-supports-yes">34</td> +<td class="bc-supports-yes">38</td> +<td class="bc-supports-yes">21</td> +<td class="bc-supports-yes">8</td> +<td class="bc-supports-yes">2.0</td> +</tr> +<tr> +<th><code>usemap</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>vspace</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +<tr> +<th><code>width</code></th> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">12</td> +<td class="bc-supports-yes">1</td> +<td class="bc-supports-yes">Yes</td> +<td class="bc-supports-yes">15</td> +<td class="bc-supports-yes">3</td> +<td class="bc-supports-yes">4.4</td> +<td class="bc-supports-yes">18</td> +<td class="bc-supports-yes">4</td> +<td class="bc-supports-yes">14</td> +<td class="bc-supports-yes">2</td> +<td class="bc-supports-yes">1.0</td> +</tr> +</tbody> +</table></div> +<h2 id="see_also">See also</h2> +<div class="section-content"><ul> <li> +<a href="picture"><code><picture></code></a>, <a href="object"><code><object></code></a>, and <a href="embed"><code><embed></code></a> elements</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit"><code>object-fit</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/object-position"><code>object-position</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation"><code>image-orientation</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering"><code>image-rendering</code></a>, and <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/image-resolution"><code>image-resolution</code></a>: Image-related CSS properties.</li> <li> +<a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement"><code>HTMLImageElement</code></a> interface for this element</li> <li><a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Images_in_HTML">Images in HTML</a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types">Image file type and format guide</a></li> <li><a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images">Responsive images</a></li> </ul></div><div class="_attribution"> + <p class="_attribution-p"> + © 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br> + <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img</a> + </p> +</div> |
