Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 5.1 — Responsive Images
HTML · Example 1 of 3

srcset and sizes: which file did the browser pick?

The pictures are small SVG images written into the code (data URIs) so this works offline. Which one you get depends on your screen, so your console may differ from someone else's.

With srcset, sizes and <picture> you list several versions of an image and let the browser download only the one that fits the screen, instead of sending a huge photo to every phone.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write an <img> for a hero banner that fills the full width on every screen, with files hero-640.jpg, hero-1280.jpg and hero-1920.jpg.

02

Write a <picture> that offers photo.avif and photo.webp before a photo.jpg fallback.

03

A product image is 100% wide below 600px, 50% wide up to 1000px, and a fixed 400px above that. Write its sizes.

Explain it without notes

01

What problem do srcset and sizes solve, and how does the browser use them to choose a file?

02

When would you use x descriptors and when w descriptors?

03

What is the difference between srcset resolution switching and <picture> art direction?

04

Why can't sizes use percentages?

srcset and sizes: which file did the browser pick?

Preview

Press Run to see the page.

Console

Nothing logged yet.