HTMLLinkElement: imageSizes property

Baseline 2023
Newly available

Since December 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The imageSizes property of the HTMLLinkElement interface indicates the size and conditions for the preloaded images defined by the imageSrcset property. It reflects the value of the <link> element's imagesizes attribute. This property can retrieve or set the imagesizes attribute value.

The <link> element's imagesizes attribute is the same as the <img> element's sizes attribute: a comma-separated source size list. Each source size includes a media condition, the size of the image as a <length>, or the keyword auto, which must come first. For more information about the syntax of the sizes attribute, see <img>.

The imagesrcset and imagesizes attributes are only relevant on <link> elements that have both a rel attribute set to preload and the as attribute set to image.

Value

A string composed of comma-separated source sizes, or the empty string "" if unspecified.

Examples

Given the following <link> element:

html
<link
  rel="preload"
  as="image"
  imagesrcset="narrow.png, medium.png 600w, wide.png 1200w"
  imagesizes="(width < 400px) 200px, (400px <= width < 600px) 75vw, 50vw" />

…we can retrieve and update the imagesizes attribute value with the imageSizes property:

js
const link = document.querySelector("link");
log(`Original: ${link.imageSizes}`);

// Change the value
link.imageSizes = "50vw";
log(`Updated: ${link.imageSizes}`);

Specifications

Specification
HTML
# dom-link-imagesizes

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
imageSizes
Chrome – Full support
Chrome 73 (Release date: 2019-03-12)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 78 (Release date: 2020-06-30)
footnote Full support
Opera – Full support
Opera 60 (Release date: 2019-04-09)
footnote Full support
Safari – Full support
Safari 17.2 (Release date: 2023-12-11)
footnote Full support
Chrome Android – Full support
Chrome Android 73 (Release date: 2019-03-12)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 52 (Release date: 2019-05-17)
footnote Full support
Safari on iOS – Full support
Safari on iOS 17.2 (Release date: 2023-12-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – Full support
WebView Android 73 (Release date: 2019-03-12)
footnote Full support
WebView on iOS – Full support
WebView on iOS 17.2 (Release date: 2023-12-11)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also