HTMLImageElement: srcset property
Baseline Widely availableThis feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
>The srcset property of the HTMLImageElement interface identifies one or more image candidate strings, separated using commas (,), each specifying image resources to use under given circumstances. Each image candidate string contains an image URL and an optional width or pixel density descriptor that indicates the conditions under which that candidate should be used instead of the image specified by the src property. It reflects the <img> element's srcset content attribute.
The srcset property, along with the sizes property, are a crucial component in designing responsive websites, as they can be used together to make pages that use appropriate images for the rendering situation.
Value
A string. For more information about the syntax of the srcset attribute, see the HTML <img> reference.
Examples
>Setting the srcset attribute
jsconst img = new Image();
img.srcset =
"/en-US/docs/Web/HTML/Reference/Elements/img/clock-demo-400px.png 2x, /en-US/docs/Web/HTML/Reference/Elements/img/clock-demo-200px.png";
img.alt = "An example picture";
Specifications
| Specification |
|---|
| HTML > # dom-img-srcset > |
Browser compatibility
See also
- HTML images
- Responsive images
- Image file type and format guide
HTMLImageElement.currentSrcHTMLImageElement.sizesHTMLImageElement.src
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Nov 7, 2025 by MDN contributors.
View this page on GitHub • Report a problem with this content