The <img> tag

The <img> tag embeds an image in the document. It's a void element — it has no closing tag.

Syntax

<img src="photo.jpg" alt="Image description">

Attributes

src The image URL. Required.
alt A text description for screen readers and for when the image fails to load. Required for accessibility.
width / height Pixel dimensions. Setting both lets the browser reserve space and avoid layout shift (CLS).
loading "lazy" defers loading until the image approaches the viewport.
srcset / sizes A list of images at different densities/sizes for responsive loading.

Example

<img src="hero.jpg" alt="Team working in the office" width="800" height="450" loading="lazy">

Notes

  • alt="" (empty) is correct for purely decorative images that carry no information.
  • Without width/height, the browser can't reserve space before the image loads, which causes content to shift.

Accessibility

  • Don't just repeat the word "image" in alt text — describe what's actually shown.
  • For complex images (charts, diagrams), alt should convey the data's meaning, not just its appearance.

Related tools