🌐Responsive Images
Also known as Responsive Image, srcset, Picture Element, Adaptive Images
Each screen gets an image of the right size. Phones load small files.
Think of it like
A café pours a small cup for a small kid. A big person gets a big cup.
Example
Emma's hero photo comes in 480, 960 and 1920 pixel widths. Phones load the small one and save over a megabyte.
Why it matters
Images are often the heaviest part of a page. Sending the right size makes pages load much faster on phones.
Definition
Example code
html
<img src="cake-960.jpg"
srcset="cake-480.jpg 480w, cake-960.jpg 960w, cake-1920.jpg 1920w"
sizes="(max-width: 600px) 100vw, 50vw"
alt="A slice of lemon cake on a white plate">Common mistake
Key takeaways
- 1Several sizes. Of the same picture.
- 2Browser chooses. Smallest that looks sharp.
- 3Crop for small. A tighter shot on phones.