Content · Web Development · HTML

HTML <source> Element Inside <picture>

Source inside picture offers alternative image candidates based on type or media conditions. The browser picks the first matching candidate it supports.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

Source inside picture offers alternative image candidates based on type or media conditions. The browser picks the first matching candidate it supports. Think about what the picture adds to the story, not just whether it looks nice on the screen.

What You Need to Know


The fallback img remains essential. The source element does not replace the alt attribute, which normally lives on img.

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


Try this markup in a fresh practice file. The next section explains the parts worth paying attention to.

This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.

<picture>
    <source type="image/avif" srcset="images/flower.avif">
    <source type="image/webp" srcset="images/flower.webp">
    <img src="images/flower.jpg" alt="Yellow flower in a garden">
</picture>

Let’s Understand the Example


  • Picture lets the browser choose between alternative image sources while keeping an img fallback.
  • Source names an alternative media or picture source for the browser to consider.
  • Type changes the kind of input, script, resource or button, depending on the element.
  • Srcset provides alternative image files for different screen sizes or pixel densities.
  • 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.

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 “Yellow flower in a garden”. 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


  1. Swap the source order and discuss why the fallback should still work.
  2. Save your changes, open or refresh the page, and compare the result with the original example.
  3. Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.

Common Beginner Mistakes


  • Writing alt on source and assuming the picture has an accessible description.
  • Never guess at an image description. Write alternative text that matches the picture and its purpose on this page.

Key Takeaways


  • Source inside picture offers alternative image candidates based on type or media conditions.
  • Picture lets the browser choose between alternative image sources while keeping an img fallback.
  • The fallback img remains essential. The source element does not replace the alt attribute, which normally lives on img.
Share this resourceSend this page to someone who may find it useful.