Course contentsShow
← Web Development
Lesson 425 of 2,9827. Responsive DesignFree lesson

The Fallback img Element

Why picture requires an img child and how it serves as the default for browsers without picture support.

The Fallback img Element

You'll learn why every <picture> element must contain an <img> as its final child.

The Safety Net Inside Picture

When you use the <picture> element for advanced responsive images, there's a critical rule: you must always include a regular <img> element as the last child. This <img> serves two vital purposes.

First, it acts as the default fallback for older browsers that don't understand the <picture> element at all. These browsers simply ignore the unfamiliar <picture> and <source> tags and render the <img> directly—just like they always have.

Second, even in modern browsers that do support <picture>, the <img> is what actually displays the chosen image. The <source> elements provide options and conditions, but the browser loads the selected URL into the <img> element. Without it, nothing would appear on screen.

Think of it like a restaurant menu with daily specials: the <source> elements are the special boards ("Today's soup if you're vegetarian"), but the <img> is the standard menu that everyone can order from—and it's also the plate that delivers whatever gets chosen.

The <img> should include its own src attribute pointing to a sensible default image (usually your smallest or most universally appropriate version) and must include an alt attribute for accessibility—this is the element screen readers interact with.

<picture>
  <source media="(min-width: 800px)" srcset="large.jpg">
  <source media="(min-width: 400px)" srcset="medium.jpg">
  <img src="small.jpg" alt="Description of the image">
</picture>

Key Takeaway: The <img> inside <picture> is mandatory—it provides backward compatibility for older browsers and is the actual element that displays the image, regardless of which source wins.