大网数据广告活动
Web 标准与前端开发

HTMLLinkElement: imageSizes property

· 52CE 我爱测

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

HTML DOM

The imageSizes property of the HTMLLinkElement interface indicates the size and conditions for the preloaded images defined by the HTMLLinkElement.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:

<link
  rel="preload"
  as="image"
  imagesrcset="narrow.png, medium.png 600w, wide.png 1200w"
  imagesizes="(width < 400px) 200px, (400px <= width < 600px) 75vw, 50vw" />
<pre id="log"></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 retrieve and update the imagesizes attribute value with the imageSizes property:

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

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

Examples

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。