HTML decoding Attribute

Beginner
6 min read
Updated: Nov 2026
3 examples
Live preview

Definition and Usage

The decoding attribute on <img> hints whether the browser should decode the image sync (with presentation), async (decode off the critical path when possible), or auto (let the UA decide).

Use async for most below-the-fold images alongside loading="lazy". Prefer sync only when you need the pixels ready in lockstep with layout painting.

Hint, not a guarantee.

Browsers may still decode when they need the pixels; decoding guides scheduling.

Do not confuse with loading.

loading controls fetch timing; decoding controls decode timing after bytes arrive.

HTML Syntax

syntax.html
<img decoding ="sync|async|auto">

Applies to img (and similarly documented for image decoding hints). Default is effectively auto.

Attribute Values

ValueDescriptionTry it
syncDecode synchronously with presentationTry it
asyncPrefer asynchronous decodeTry it
autoBrowser chooses (default)Try it

Live Preview

Switch decoding on a sample image. Effect is subtle — check DevTools performance in real apps.

Attribute updates immediately; decode scheduling is browser-internal.

Result
CodeToFun logo

decoding="async"

HTML Examples

Example 1 — Async Decode for Galleries

Prefer async decode for non-critical images.

HTML
<img src="/images/gallery.webp" alt="Workshop"
     width="800" height="500" loading="lazy" decoding="async">
Try It Yourself

How It Works

  1. Set decoding="async" for most content images.
  2. Pair with loading="lazy" when offscreen.
  3. Keep width/height to reduce layout shift.
  4. Use meaningful alt text.

Example 2 — Sync Decode When Needed

Request synchronous decode when presentation must wait for pixels.

HTML
<img src="/images/critical.webp" alt="Diagram"
     width="640" height="360" decoding="sync">
Try It Yourself

How It Works

  1. Use sync sparingly — it can block presentation.
  2. Prefer async or auto for typical pages.
  3. Hero LCP images more often need fetchpriority/loading than sync decode.
  4. Measure before forcing sync in production.

Example 3 — Let the Browser Decide

auto (or omitting decoding) leaves scheduling to the UA.

HTML
<img src="/images/photo.webp" alt="Portrait"
     width="400" height="400" decoding="auto">
Try It Yourself

How It Works

  1. auto is the default-like choice.
  2. Explicit async documents intent for content images.
  3. Works with srcset/sizes the same way.
  4. Not a substitute for compressed assets.

Edge Cases & Pitfalls

decoding is a scheduling hint — compress and size images correctly first.

loading

Different from loading

loading=lazy defers fetch; decoding affects decode after bytes arrive.

css

Not for background-image

CSS backgrounds ignore the HTML decoding attribute.

subtle

Hard to see in demos

Benefits show up under load with many large images.

svg

Raster focus

Most relevant for photographic/raster img content.

Browser Support

decoding is an HTML attribute for browsers. It is not a Node.js, Deno, or Bun API.

✓ Widely available

decoding

Supported in modern Chromium, Firefox, and Safari for img decoding hints.

94% Global support (approx.)
Google Chrome 65+
Full support
Mozilla Firefox Yes
Full support
Apple Safari Yes
Full support
Microsoft Edge Yes
Full support
Opera Yes
Full support
Samsung Internet Yes
Full support
Internet Explorer No support
Not supported
decoding Widely supported

Bottom line: Default to decoding="async" for content images; keep loading separate.

Key Takeaways

  • Values: sync, async, auto.
  • Default practice: async for most imgs.
  • Not loading: fetch timing is a different attribute.
  • Hint only: browsers may still decode when needed.

One line: decoding="async" prefers decoding images off the critical path.

Frequently Asked Questions

It hints whether the browser should decode an image synchronously with presentation, asynchronously, or decide automatically.
Prefer async for most content images. Use sync only when you specifically need decode tied to presentation.
No. loading controls when the resource is fetched; decoding controls how/when pixels are decoded.
Omitting decoding is treated like auto — the browser decides.
Yes. A common pattern is loading="lazy" decoding="async".
Usually not in small demos. The benefit is smoother main-thread work under load.

Next: default

Mark the default track in media elements.

default tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful