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
<img src="photo.jpg" alt="Description">Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| alt | text | Text equivalent for the image purpose; empty for genuinely decorative content. Do not omit alt as a normal authoring practice. |
| src | URL | Image candidate URL. srcset and sizes may affect actual selection; use currentSrc to inspect the selected URL. |
| srcset | image candidate list | Lists 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. |
| sizes | responsive source size list or icon sizes | On responsive images, describes the expected display slot width used with width-descriptor candidates. On icon links, describes icon dimensions. The grammars differ. |
| crossorigin | enumerated: anonymous, use-credentials | Configures CORS settings for eligible resource requests. anonymous omits cross-origin credentials; use-credentials includes them. Server CORS headers must permit the request when needed. |
| usemap | fragment reference | Associates an image with a named map in the document. Use # followed by the map name; provide meaningful alternatives for its linked areas. |
| ismap | boolean | Makes 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. |
| width | non-negative integer | Defines 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. |
| height | non-negative integer | Sets 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. |
| referrerpolicy | referrer policy keyword | Controls 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. |
| decoding | enumerated: sync, async, auto | Hints 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. |
| loading | enumerated: eager, lazy | Hints 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. |
| fetchpriority | enumerated: high, low, auto | Hints 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
Content model: Empty; this void element cannot contain children and must not have an end tag. No closing tag.
Working Example
<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