Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLLinkElement
  4. imageSrcset

HTMLLinkElement: imageSrcset 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.

TheimageSrcset property of theHTMLLinkElement interface is a string which identifies one or more comma-separatedimage candidate strings. This property reflects the value of the<link> element'simagesrcset attribute. This property can retrieved or set theimagesrcset attribute value.

Each image candidate string contains an image URL and an optional width and/or pixel density descriptor indicating the conditions under which that candidate image should be used.

"images/team-photo.jpg, images/team-photo-retina.jpg 2x, images/team-photo-large.jpg 1400w"

For HTML<link> elements withrel="preload" andas="image" set, theimagesrcset attribute has similar syntax and semantics as the<img> element'ssrcset attribute, which indicates to preload the appropriate resource used by an<img> element with corresponding values for itssrcset andsizes attributes.

If theimageSrcset property includes width descriptors, theimageSizes property must be non-null, or theimageSrcset value will be ignored.

Value

A string composed of a comma-separated list of one or more image candidate strings, or the empty string"" if unspecified..

Examples

Given the following<link> element:

html
<link  rel="preload"  as="image"  imagesizes="50vw"  imagesrcset="bg-narrow.png, bg-wide.png 800w" />
<pre></pre>
#log {  padding: 0 0.25rem;  font-size: 1.2em;  line-height: 1.4;}
const logElement = document.querySelector("#log");function log(text) {  logElement.innerText = `${logElement.innerText}${text}\n`;  logElement.scrollTop = logElement.scrollHeight;}

…we can access theimagesrcset attribute value, and update it, using theimageSrcset property:

js
const link = document.querySelector("link");log(`Original: ${link.imageSrcset}`);// add an image candidate stringlink.imageSrcset += ", bg-huge.png 1200w";log(`Updated: ${link.imageSrcset}`);

Specifications

Specification
HTML
# dom-link-imagesrcset

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp