The sizes attribute tells the browser the intended display width of an <img> (or <source>) when srcset uses width descriptors (500w, 1000w, …).
Write a comma-separated list of media condition + length, ending with a default length (for example (max-width: 600px) 100vw, 800px). Default if omitted: 100vw. Not the same as the form size attribute.
Baseline · Widely available.
Not deprecated. Stable with responsive images across modern browsers (widely since about March 2016).
Only with w descriptors.
MDN: put sizes when srcset uses width descriptors. Density descriptors (1x/2x) do not use sizes.
Syntax
HTML Syntax
syntax.html
<img srcset="…" sizes="source-size-list" …>
A source-size list is comma-separated entries like (max-width: 600px) 100vw, ending with a bare length such as 50vw or 800px.
auto needs layout + lazy load support; fallbacks follow the comma list.
How It Works
auto uses the concrete layout width after CSS.
loading="lazy" — MDN expects lazy loading so layout exists before selection.
Fallbacks after auto help browsers that do not understand auto.
width/height still reserve space and reduce layout shift.
Edge Cases & Pitfalls
Most mistakes are wrong layout hints or mixing descriptor types.
pair
sizes needs w descriptors
If srcset only has 1x/2x, skip sizes. Do not mix w and x in one srcset.
layout
Match real CSS width
If CSS shows the image at 400px but sizes says 100vw, the browser may over-fetch.
dpr
Device pixel ratio multiplies the slot
A 400px slot on a 2× screen often needs an ~800w file. That is expected — not a bug.
name
sizes ≠ size
size is for form controls. sizes is for responsive images.
auto
auto needs lazy + fallbacks
Use loading="lazy" and list classic sizes after auto for older browsers. Support for auto is newer than basic sizes.
Compatibility
Browser Support
sizes is an HTML attribute for responsive img/source selection with srcset width descriptors.
✓ Baseline · Widely available
sizes
Widely available since about March 2016 for classic source-size lists. The auto keyword is newer and intended with lazy loading.
96%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet ExplorerNo support
Not supported
sizesWidely supported
Bottom line: Safe for responsive images with w descriptors. Keep a src fallback; add sizes that match your real CSS layout.
Remember
Key Takeaways
Role: layout-width hint for srcsetw candidates.
Syntax: media condition + length, then a default length.
Default: omitted sizes behaves like 100vw.
Accuracy: mirror your CSS layout or you waste bandwidth.
One line:srcset lists files — sizes says how wide they will look.
Frequently Asked Questions
With srcset width (w) descriptors, sizes tells the browser how wide the image will display under different layout conditions so it can pick the smallest adequate file.
Primarily img (and source inside picture) when srcset uses w descriptors. link can also use sizes with icon imagesrcset. It is not the form size attribute.
Usually no. Pixel-density descriptors (1x, 2x) do not use sizes. Width descriptors (500w, 1000w) should be paired with sizes.
The default is 100vw — the browser assumes the image is as wide as the viewport when choosing from srcset.
auto lets the browser use the image’s expected layout width after CSS. It is intended with loading=lazy. Add fallback sizes after auto for older browsers.
No. size is for input/select visible control size. sizes is for responsive image layout width with srcset.