Home HTML Attributes decoding HTML decoding Attribute Definition
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.
Syntax
HTML Syntax <img decoding ="sync |async |auto ">
Applies to img (and similarly documented for image decoding hints). Default is effectively auto.
Values
Attribute Values Value Description Try it syncDecode synchronously with presentation Try itasyncPrefer asynchronous decode Try itautoBrowser chooses (default) Try it
Try it
Live Preview Switch decoding on a sample image. Effect is subtle — check DevTools performance in real apps.
Code
HTML Examples 1. async 2. sync 3. auto Example 1 — Async Decode for Galleries Prefer async decode for non-critical images.
<img src="/images/gallery.webp" alt="Workshop"
width="800" height="500" loading="lazy" decoding="async"> decoding="async" with lazy loading.
How It Works Set decoding="async" for most content images.Pair with loading="lazy" when offscreen.Keep width/height to reduce layout shift.Use meaningful alt text.Example 2 — Sync Decode When Needed Request synchronous decode when presentation must wait for pixels.
<img src="/images/critical.webp" alt="Diagram"
width="640" height="360" decoding="sync"> decoding="sync" — rare; prefer async for most images.
How It Works Use sync sparingly — it can block presentation.Prefer async or auto for typical pages.Hero LCP images more often need fetchpriority/loading than sync decode.Measure before forcing sync in production.Example 3 — Let the Browser Decide auto (or omitting decoding) leaves scheduling to the UA.
<img src="/images/photo.webp" alt="Portrait"
width="400" height="400" decoding="auto"> decoding="auto" — browser default behavior.
How It Works auto is the default-like choice .Explicit async documents intent for content images.Works with srcset/sizes the same way.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.
Compatibility
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.
Remember
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 What does the decoding attribute do? It hints whether the browser should decode an image synchronously with presentation, asynchronously, or decide automatically.
Should I use async or sync? Prefer async for most content images. Use sync only when you specifically need decode tied to presentation.
Is decoding the same as loading? No. loading controls when the resource is fetched; decoding controls how/when pixels are decoded.
What is the default? Omitting decoding is treated like auto — the browser decides.
Does it work with lazy loading? Yes. A common pattern is loading="lazy" decoding="async".
Will I see a big visual change? Usually not in small demos. The benefit is smoother main-thread work under load.
CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
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
Helpful Share Copy link Suggestion