DOM Methods

HTMLImageElement.decode()

Returns a promise that resolves when the selected image can be decoded for rendering. It rejects if decoding fails or the source changes before decoding completes. Useful before swapping images; it does not guarantee the next paint time. Example result: 12.

Formal Syntax & Structure

html syntaxhtml
image.decode()

Return Value

Promise<void>

Resolves after successful decoding.

Working Example

Example Snippethtml
<p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  const image = new Image(); image.src = "data:image/svg+xml," + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="12" height="8"><rect width="12" height="8" fill="green"/></svg>');  await image.decode(); result.textContent = image.naturalWidth;  })().catch(error => { result.textContent = "Error: " + error.name; });</script>

Browser Compatibility

Minimum supported versions across modern rendering engines

Widely Available (2020)
Blink
Chrome
64+
Yes
Blink
Edge
79+
Yes
Gecko
Firefox
68+
Yes
WebKit
Safari
11.1+
Yes
Blink
Opera
51+
Yes
Basic image decoding promise is widely available. Baseline interoperability since January 2020.
HTML Living Standard
HTML Reference