Lazy loading can postpone images that are far below the visible page, helping the first screen appear faster. Think about what the picture adds to the story, not just whether it looks nice on the screen.
What You Need to Know
Avoid lazy loading the main hero image near the top of the page. Width and height attributes also help prevent layout shifts while an image waits to load.
Pictures can make a page much easier to understand, but they are useful only when the file loads and the important meaning is also available as text.
Example: See It in Action
This example keeps the idea small. Copy it carefully, then follow the explanation instead of guessing what the browser will do.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<section>
<h2>Photos from the trip</h2>
<img src="images/trip-1.jpg" alt="Forest path" loading="lazy" width="800" height="600">
<img src="images/trip-2.jpg" alt="Mountain lake" loading="lazy" width="800" height="600">
</section>
Let’s Understand the Example
- Img displays an image. Src chooses the file and alt provides a useful text alternative.
- Section groups content around a shared topic and usually has a heading.
- Loading can ask the browser to defer offscreen media, but important first-screen content usually should not be lazy.
- Src tells the browser where to find an image or other embedded resource.
- Alt supplies a text alternative for an image. Empty alt is appropriate for purely decorative images.
- Width gives a useful size hint; for images, accurate dimensions help the browser reserve space.
An image appears only if its file path is correct. If it is informative, its alt text should share the same useful meaning; if it is decoration, empty alt text is often right.
What Should You See?
If the image file is available, the picture appears in the page. If not, the browser may show a broken image or fallback text. The example alt text is “Forest path”. Check that the text alternative fits the picture’s purpose.
Cover the picture and read the surrounding text aloud. If essential information has disappeared, add a useful text alternative or nearby explanation.
Try It Yourself
- Make one gallery picture eager and one below-the-fold picture lazy.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Adding loading="lazy" to every image, including the first important image.
- Never guess at an image description. Write alternative text that matches the picture and its purpose on this page.
Key Takeaways
- Lazy loading can postpone images that are far below the visible page, helping the first screen appear faster.
- Img displays an image. Src chooses the file and alt provides a useful text alternative.
- Avoid lazy loading the main hero image near the top of the page. Width and height attributes also help prevent layout shifts while an image waits to load.