Images & Media

HTML <img> element

Embeds an image. Provide a meaningful alt text alternative, or empty alt for a purely decorative image. Width and height can reserve layout space. The example embeds a small SVG image as a data URL so it works offline; ordinary sites can use a real image file. Images are replaced content; the browser lays out an image box and loads an external or embedded image resource. Reserve space with intrinsic width and height. Use srcset and sizes for responsive image selection, or picture for art direction. Alternative text depends on the purpose of the image, not just its appearance. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<img src="photo.jpg" alt="Description">

Parameters & Attributes

NameTypeDescription
alttextText equivalent for the image purpose; empty for genuinely decorative content. Do not omit alt as a normal authoring practice.
srcURLImage candidate URL. srcset and sizes may affect actual selection; use currentSrc to inspect the selected URL.
srcsetimage candidate listLists image URLs with width or pixel-density descriptors. The browser selects a candidate based on the display environment; use sizes with width descriptors and provide an img fallback.
sizesresponsive source size list or icon sizesOn responsive images, describes the expected display slot width used with width-descriptor candidates. On icon links, describes icon dimensions. The grammars differ.
crossoriginenumerated: anonymous, use-credentialsConfigures CORS settings for eligible resource requests. anonymous omits cross-origin credentials; use-credentials includes them. Server CORS headers must permit the request when needed.
usemapfragment referenceAssociates an image with a named map in the document. Use # followed by the map name; provide meaningful alternatives for its linked areas.
ismapbooleanMakes an image inside a hyperlink submit click coordinates to the linked URL as a server-side image map. Prefer accessible ordinary links for navigation where practical.
widthnon-negative integerDefines element-specific width, commonly in CSS pixels. On images it can establish an intrinsic aspect ratio together with height; on canvas it sets the bitmap width.
heightnon-negative integerSets an element-specific height, commonly in CSS pixels. On images, pair it with width matching the intrinsic aspect ratio to reserve layout space. It is not a CSS length with units.
referrerpolicyreferrer policy keywordControls the referrer information sent with an eligible fetch or navigation. no-referrer omits it; strict-origin-when-cross-origin is a common default policy. It does not prevent all tracking.
decodingenumerated: sync, async, autoHints how the browser should schedule image decoding relative to other content. It does not change the image format or guarantee a particular paint time; auto is the default.
loadingenumerated: eager, lazyHints whether supported images or iframes should be loaded immediately or deferred until near the viewport. Avoid lazy-loading the likely largest visible content at the top of the page.
fetchpriorityenumerated: high, low, autoHints relative fetch priority for eligible resources. It is not a guarantee and does not replace preloading or lazy loading. Reserve high for genuinely important resources.

Return Value

HTMLImageElement

Content model: Empty; this void element cannot contain children and must not have an end tag. No closing tag.

Working Example

Example Snippethtml
<img src="data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22320%22%20height=%22200%22%3E%3Crect%20width=%22320%22%20height=%22200%22%20fill=%22navy%22/%3E%3C/svg%3E" alt="Solid navy rectangle" width="320" height="200">

Browser Compatibility

Minimum supported versions across modern rendering engines

Widely Available (2015)
Blink (modern)
Chrome
1
Yes
EdgeHTML / Blink
Edge
12
Yes
Gecko
Firefox
1
Yes
WebKit
Safari
1
Yes
Support for this specific feature in the checked browser data. Subfeatures may differ.
HTML Living Standard
HTML Reference