CKTIS / HTML
img — embedding an image
The img element embeds an image in an HTML document. The src and srcset attributes identify resources, while alt supplies text that replaces the information conveyed by the image.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<img src="image-url" alt="text alternative" width="160" height="100">img represents an image. It is a void element: it has neither child content nor an end tag. At least one of src or srcset is required; src must contain a nonempty image URL.
Normally, provide alt that conveys the image's meaning in context, rather than its filename. For a purely decorative image, use alt="". Missing alt is not equivalent to empty alternative text; omission is permitted only in limited cases defined by the standard.
width and height help the browser reserve space before the image loads. srcset offers alternatives for the browser to select. With width descriptors w, sizes is required unless the img element allows auto-sizes. For example, with loading="lazy", which allows image loading to be deferred, sizes may be omitted.
The example embeds an SVG image in a data: URL, so it needs no separate file or network connection. The expected result is a blue rectangle measuring 160 × 100 CSS pixels.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Image example</title>
<img
src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='160'%20height='100'%3E%3Crect%20width='160'%20height='100'%20fill='blue'/%3E%3C/svg%3E"
alt="Blue rectangle"
width="160"
height="100">
</html>Result
A blue rectangle, 160 CSS pixels wide and 100 CSS pixels high.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.