Course contentsShow
← Web Development
Lesson 1234 of 2,98222. Responsive Images and MediaFree lesson

The Mandatory <img> Fallback

Understand why picture requires a child img element and how it serves as the fallback and sizing reference.

The Mandatory <img> Fallback

You'll learn why every <picture> element must contain an <img> child and what critical roles it plays.

When working with the <picture> element for art direction, there's a rule you cannot break: you must include an <img> element as the last child. This isn't optional—it's required by the HTML specification.

Why the <img> is Mandatory

Think of <picture> as a wrapper that suggests different image sources, but the <img> inside is what actually displays the image. The browser evaluates all the <source> elements you've provided, picks the best match based on media conditions, but ultimately renders the chosen image through that inner <img> element.

The <img> serves three essential purposes:

  1. Fallback for older browsers: Browsers that don't understand <picture> will ignore it entirely and just render the <img>, ensuring your content still displays.

  2. The actual rendering element: Even in modern browsers, the <img> is what shows the image on screen. <picture> doesn't render anything by itself—it only directs which source the <img> should use.

  3. Sizing and layout reference: The <img> element provides the dimensions, alt text, and layout properties. Attributes like width, height, alt, and loading all go on the <img>, not the <picture>.

Analogy

Imagine <picture> as a restaurant menu with daily specials (your <source> elements), but the <img> is the actual plate that delivers food to your table. Without the plate, nothing gets served.

Key Takeaway: The <img> element inside <picture> is mandatory—it provides the fallback, handles rendering, and defines sizing and accessibility attributes for the entire responsive image.