Lesson 53 of 55
HTMLImages
9 min
Course progress96%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 53 of 55
HTML9 min
Keep these ideas in mind as you work through the lesson.
<img>)<img src='images/photo.jpg' alt='Sunset over the mountains' width='600' height='400' loading='lazy' srcset='images/photo-600.jpg 600w, images/photo-1200.jpg 1200w' sizes='(max-width: 600px) 100vw, 600px' />
src – Path to the image file.alt – Mandatory text for screen readers and when the image fails to load. Write concise, descriptive sentences.width/height – Reserve the exact space the image will occupy; this prevents layout shift (important for Core Web Vitals).loading='lazy' – Defers off‑screen images until they approach the viewport.srcset and sizes – Serve responsive images for different viewport widths and pixel densities.srcset to offer 1× and 2× (or higher) variants for high‑DPI displays.alt='' to hide them from assistive technology.alt attribute present and meaningful? ✅loading='lazy' for non‑above‑the‑fold images? ✅srcset/sizes for responsive delivery? ✅Tip: Run your page through Google Lighthouse → Performance → Avoid large layout shifts to confirm images are not causing CLS.
Replace the src with a WebP version, add a srcset that includes a 2× image, and watch the network panel show the appropriate file being downloaded based on your screen’s pixel density.