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
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.