The HTML sizes attribute
Quick answer
The HTML sizes attribute tells the browser the rendered size of the image for different viewport conditions, so it can choose a srcset candidate. It is used on the <img>, <source> and <link> elements.
Overview
The sizes attribute defines image display size for srcset selection. It is used on the <img>, <source> and <link> elements.
It relates to images: their source and responsive variants, dimensions, and loading and decoding behavior. Setting the right attributes keeps images sharp, fast and accessible.
Syntax
<img srcset="s.jpg 480w, l.jpg 1080w" sizes="(max-width:600px) 480px, 1080px" src="l.jpg" alt="">
Values
| Value |
|---|
A comma-separated list of media-condition / length pairs, e.g. (max-width:600px) 480px, 1080px. |
Best practices
Frequently asked questions
What does the sizes attribute do?
Defines image display size for srcset selection.