The <img> element embeds an image. It's a void element with two key attributes: src (where the image is) and alt (a text description).
The img element
<img src="cat.jpg" alt="A ginger cat sleeping on a sofa"width="400" height="300" loading="lazy" />
Why alt text matters
Modern images
The <picture> element and srcset serve different image sizes/formats for different screens — the responsive-images pattern for performance.
Key takeaways
- 01<img> embeds an image; src is the source, alt is the text description.
- 02Always provide meaningful alt text (empty alt="" for decorative images).
- 03Set width/height to prevent layout shift; loading="lazy" defers off-screen images.
- 04<picture>/srcset serve responsive images for different screens.
