Responsive image sets
Almost every width list on the internet was copied from another width list. Yours can be derived instead, and the derivation takes about ten minutes with the stylesheet open.
Where the numbers come from
A candidate file is only useful if some real device will choose it. Which files a device chooses is decided by two things you control — the rendered width of the picture at that viewport, and what you told the browser that width would be — and one you do not, the screen’s pixel density. So the list is built from the layout outwards, in four steps:
- Write down every breakpoint at which the picture’s box changes size.
- At each one, work out the widest the box can be, in CSS pixels.
- Double each of those for the dense screens you intend to serve properly.
- Sort, round, and throw away anything that sits within a quarter of its neighbour.
Step two is the one people skip, and it is arithmetic rather than judgement. Take a grid: a container that stops growing at 1200 pixels with 24-pixel gutters, three columns above 1024, two above 640, one below it. The picture is never wider than its column, so:
| Viewport | Columns | Widest the box gets | ×1, ×2 |
|---|---|---|---|
| under 640 | 1 | container minus gutters, so about 592 | 592, 1184 |
| 640 to 1023 | 2 | (1024 − 72) ÷ 2, so about 476 | 476, 952 |
| 1024 and up | 3 | (1200 − 96) ÷ 3, so 368 | 368, 736 |
That yields eight candidates: 368, 476, 592, 736, 952, 1184 and their duplicates. Round them outward to the nearest sensible number, drop the pairs that are close together, and the list is 400, 600, 800, 1200. Four files, and every one of them is the file some real device will ask for. Notice what is not in the list: 1920, which nothing in this layout can ever use.
The widest box is not the viewport
The single most common mistake is building the list from screen sizes — 1920, 2560, because monitors are that wide. A picture in a three-column grid on a 2560 monitor is still 368 CSS pixels across. Serving it a 1920-wide file is not generosity, it is a megabyte spent on a picture that will be drawn at a seventh of its size, and the browser only avoids doing that if the list gives it something better to pick.
How far apart is far enough
Bytes go up roughly with area, so a file 40% wider than its neighbour is about twice the size. That is the frame for the spacing question: a gap is too wide when a device landing in the middle of it is made to download something noticeably larger than it needs, and too narrow when you are writing files that differ by a few kilobytes.
| Step between widths | Worst-case waste | Verdict |
|---|---|---|
| 1.15× | about 30% extra pixels | Too fine. You are paying for files nobody distinguishes. |
| 1.3× | about 70% extra pixels | A good default for anything large on the page. |
| 1.6× | about 2.5× the pixels | Acceptable for thumbnails, where the absolute numbers are tiny. |
| 2.5× | over 6× the pixels | Too coarse. Something in the middle will hurt. |
Four to six widths covers almost every layout. Past that you are adding files to the archive and rows to the plan for a difference that the encoder’s quality setting is already larger than.
When a second pixel ratio earns its bytes
A ×2 file is four times the pixels of its ×1, and it buys a visible difference in exactly one situation: hard edges viewed closely. A photograph of a landscape at ×1 on a dense phone screen looks soft to someone looking for softness. A product shot with a printed label on it, a screenshot, a diagram or anything containing type looks wrong immediately.
- Photographs, large on the page: ×1 and ×2, and let the quality setting fall a little on the ×2.
- Small tiles under about 400 pixels: ×1 and ×2, because both files are cheap anyway.
- Screenshots, diagrams and anything with lettering in it: ×2 is not optional.
- ×3: only for marks and avatars, where the file is a few kilobytes and the edges are geometric.
There is no separate mechanism for this. A ratio variant is just another width, and once the set has been expanded the ×2 of a 600 and a plain 1200 are the same file asked for twice — which is why deduplicating the sorted list at the end of step four matters more than it looks.