HTML Image Loading, Decoding and Priority
Choose eager or lazy loading
loading="lazy" asks the browser to defer images that are not near the visible viewport. eager is the normal immediate-loading behavior. Avoid lazy loading a likely main visible image. Always supply dimensions so deferred images reserve space. Browser thresholds vary.
<img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22320%22%20height%3D%22160%22%20viewBox%3D%220%200%20320%20160%22%3E%3Crect%20width%3D%22320%22%20height%3D%22160%22%20fill%3D%22%23dbeafe%22%2F%3E%3Cpath%20d%3D%22M0%20160%20L160%2032%20L320%20160Z%22%20fill%3D%22%23166534%22%2F%3E%3C%2Fsvg%3E" alt="Green hill" width="320" height="160" loading="eager"><div style="height: 900px">Scroll to the second image.</div><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22160%22%20height%3D%2280%22%20viewBox%3D%220%200%20160%2080%22%3E%3Crect%20width%3D%22160%22%20height%3D%2280%22%20fill%3D%22%23dbeafe%22%2F%3E%3Cpath%20d%3D%22M0%2080%20L80%2016%20L160%2080Z%22%20fill%3D%22%23166534%22%2F%3E%3C%2Fsvg%3E" alt="Green hill" width="160" height="80" loading="lazy">The lower image has a lazy-loading hint. The browser decides when to request it; embedded data does not demonstrate network savings.
Separate decoding from loading
Decoding converts image data into a drawable representation. decoding="async" requests asynchronous decoding, sync requests synchronous presentation and auto leaves the preference to the browser. These are hints, not promises about painting order or network fetching.
<img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22320%22%20height%3D%22160%22%20viewBox%3D%220%200%20320%20160%22%3E%3Crect%20width%3D%22320%22%20height%3D%22160%22%20fill%3D%22%23dbeafe%22%2F%3E%3Cpath%20d%3D%22M0%20160%20L160%2032%20L320%20160Z%22%20fill%3D%22%23166534%22%2F%3E%3C%2Fsvg%3E" alt="Green hill" width="320" height="160" decoding="async">The image declares a decoding preference. Its appearance need not change.
Prioritize only meaningful resources
fetchpriority accepts high, low or auto. It hints at the relative importance of fetching a resource, not whether an image is visible or decoded. Use high sparingly for important visible images; giving everything high priority defeats the distinction. Measure in browser developer tools with realistic network conditions.
<img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22320%22%20height%3D%22160%22%20viewBox%3D%220%200%20320%20160%22%3E%3Crect%20width%3D%22320%22%20height%3D%22160%22%20fill%3D%22%23dbeafe%22%2F%3E%3Cpath%20d%3D%22M0%20160%20L160%2032%20L320%20160Z%22%20fill%3D%22%23166534%22%2F%3E%3C%2Fsvg%3E" alt="Main green hill" width="320" height="160" fetchpriority="high"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%220%200%2024%2024%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%228%22%20fill%3D%22gold%22%2F%3E%3C%2Fsvg%3E" alt="" width="24" height="24" fetchpriority="low">The main image and decorative icon declare different priority hints; this offline example does not measure their effect.
Practice and next steps
Choose loading and priority hints for a visible main image and a below-the-fold illustration; explain each choice.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Image Loading, Decoding and Priority — Knowledge Check
Check the core concepts from this lesson.
Which image should normally not be lazy loaded?
What does decoding="async" control?
What does fetchpriority="high" guarantee?
Why should you measure before using fetchpriority="high" on many images?
Which attribute asks the browser to defer eligible offscreen image loading?