Command Palette

Search for a command to run...

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

picture: the first matching source wins

The first source is skipped because no browser knows the type image/x-future. Then a narrow preview shows the close-up and a wide one shows the wide crop. Drag the preview wider or narrower and press Run.

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?

picture: the first matching source wins

Preview

Press Run to see the page.

Console

Nothing logged yet.