How to lazy load images in websites the easy way?

October 24, 2020 - 1 min read

Lazy loading images is one of the techniques to decrease the initial page load of a website and to increase performance. Lazy loading images on websites is pretty easy these days.

To lazy load images natively in the browser, you can declare the loading attribute to be lazy in the image tag.

<!-- Lazy Loads Images -->
<img src="" loading="lazy" />

Adding loading="lazy" will help to reduce the initial page load of a website.

If you don't want lazy loading in some images or want the images to load when the website loads, then you can use the loading="eager" attribute in the image tag or not having a loading attribute in the first place 🙂.

<!-- Loads Images When Website Loads -->
<img src="" loading="eager" />

<!-- OR not use the loading attribute -->
<img src="" />

See the compatibility for various browsers on Can I Use.

See this example live in JSBin.

Feel free to share if you found this useful 😃.