The HTML imagesrcset attribute
Quick answer
The HTML imagesrcset attribute provides a responsive srcset for a preloaded image, mirroring an <img> srcset. It is used on the <link rel="preload" as="image"> element.
Overview
The imagesrcset attribute provides a responsive srcset for a preloaded image, mirroring an <img> srcset. It applies to the <link rel="preload" as="image"> element.
It lets you preload the same responsive image the browser will later pick for an <img>, pairing with imagesizes.
Syntax
<link rel="preload" as="image" imagesrcset="s.jpg 480w, l.jpg 1080w" imagesizes="100vw">
Values
| Value |
|---|
| A srcset string — comma-separated "URL descriptor" 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 imagesrcset attribute do?
Sets a responsive srcset for a preloaded image.