How to Lazy Load Images Natively in HTML
Simply use loading=βlazyβ
in img
tags to lazy load them.
Copied to clipboard!
<!-- Use the loading attribute on images to defer the loading of offscreen images -->
<img src="lazy-loading.jpg" loading="lazy" />
Please note that this feature is not widely supported, which means you need to provide fallback solutions. For the full list of supported browsers, check out the support table on caniuse.com.
If your browser does not support the loading
attribute, it will simply ignore it, so you don't have to worry about introducing bugs.
Resources:
π More Webtips
Master the Art of Frontend
- Access 100+ interactive lessons
- Unlimited access to hundreds of tutorials
- Prepare for technical interviews