HTMLImageElement: srcset property - Web APIs | MDN

Value

A string. For more information about the syntax of the srcset attribute, see the HTML <img> reference.

Examples

Setting the srcset attribute

js

const 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

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.