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

decoding

· 52CE 我爱测

The `decoding` attribute, valid on image elements, provides a hint to the browser as to whether it should perform image decoding along with rendering other content in a single presentation step that looks more "correct" (`sync`), or render and present the other content first and

The decoding attribute, valid on image elements, provides a hint to the browser as to whether it should perform image decoding along with rendering other content in a single presentation step that looks more "correct" (sync), or render and present the other content first and then decode the image and present it later (async). In practice, async means that the next paint does not wait for the image to decode.

It is often difficult to perceive any noticeable effect when using decoding on static <image> elements. They'll likely be initially rendered as empty images while the image files are fetched (either from the network or from the cache) and then handled independently anyway, so the "syncing" of content updates is less apparent. However, the blocking of rendering while decoding happens, while often quite small, can be measured — even if it is difficult to observe with the human eye.

Using different decoding types can result in more noticeable differences when dynamically inserting <image> elements into the DOM via JavaScript — see SVGImageElement.decoding for more details.

Allowed values:

  • sync
    • : Decode the image synchronously along with rendering the other content, and present everything together.
  • async
    • : Decode the image asynchronously, after rendering and presenting the other content.
  • auto
    • : No preference for the decoding mode; the browser decides what is best for the user. This is the default value.

Example

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
  <image
    href="https://example.com/mdn_logo_dark.png"
    height="200"
    width="200"
    decoding="async" />
</svg>

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

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

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