📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials HTML Fundamentals Images

Images

5 min read Quiz at the end
Add images with img. Always include a descriptive alt attribute for accessibility and SEO. Set width and height attributes to prevent layout shift. Use loading='lazy' for images that start below the visible area.

Images

<!-- Basic image -->
<img src="photo.jpg" alt="A beautiful photo" width="800" height="600">

<!-- Lazy loading -->
<img src="hero.jpg" alt="Hero" loading="lazy">

<!-- Responsive image -->
<picture>
    <source srcset="photo.webp" type="image/webp">
    <img src="photo.jpg" alt="Photo">
</picture>

Always write descriptive alt text for accessibility.

Sign in to track your progress.
Topic Quiz · 5 questions

Test your understanding before moving on

1. The alt attribute is for:
💡 alt text describes the image for screen readers and appears when the image fails to load.
2. Which loading value defers offscreen images?
💡 loading="lazy" defers loading until the image is near the viewport.
3. Which element provides multiple format options?
💡 <picture> with <source> elements provides multiple format/resolution options.
4. What should alt be for decorative images?
💡 Decorative images should have alt="" so screen readers skip them.
5. Why set explicit width and height on images?
💡 Setting width and height reserves space and prevents Cumulative Layout Shift.