The HTML imagesizes attribute
Quick answer
The HTML imagesizes attribute provides the sizes hint for a preloaded responsive image, mirroring an <img> sizes. It is used on the <link rel="preload" as="image"> element.
Overview
The imagesizes attribute sets the sizes hint for a preloaded image. It is used on document head elements like <meta>, <link> and <script>.
It belongs to the document head — metadata, stylesheet and script loading, encoding and resource hints. These attributes shape how the page is interpreted and how efficiently its resources load.
Syntax
<link rel="preload" as="image" imagesrcset="s.jpg 480w, l.jpg 1080w" imagesizes="(max-width:600px) 480px, 1080px">
Values
| Value |
|---|
| A sizes string — media-condition / length pairs. |
Best practices
- Declare the character encoding with <meta charset="utf-8"> first in the <head>.
- Load scripts with defer (or as modules) so they do not block parsing.
- Protect third-party resources with integrity and crossorigin (Subresource Integrity).
- Use resource hints like preload deliberately, paired with the right as value.
Frequently asked questions
What does the imagesizes attribute do?
Sets the sizes hint for a preloaded image.