Picture lets a page use a different crop when screen conditions change. That is called art direction: showing the most useful part of the picture on narrow and wide screens. Think about what the picture adds to the story, not just whether it looks nice on the screen.
What You Need to Know
Source elements inside picture are tried in order. Keep the img as the fallback, with suitable alt text and dimensions.
Example: See It in Action
Take a look at this small piece of HTML. You can use it in a practice document and change the text to make it your own.
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 media="(max-width: 600px)" srcset="images/portrait-crop.jpg">
<img src="images/group-photo.jpg" alt="Friends at the school fair" width="960" height="640">
</picture>
Let’s Understand the Example
- Picture lets the browser choose between alternative image sources while keeping an img fallback.
- Img displays an image. Src chooses the file and alt provides a useful text alternative.
- Media specifies when a source or stylesheet applies.
- 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 “Friends at the school fair”. 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
- Change the mobile image to a tighter crop and resize the viewport.
- 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
- Forgetting img inside picture and leaving no ordinary fallback.
- Never guess at an image description. Write alternative text that matches the picture and its purpose on this page.
Key Takeaways
- Picture lets a page use a different crop when screen conditions change.
- Picture lets the browser choose between alternative image sources while keeping an img fallback.
- Source elements inside picture are tried in order. Keep the img as the fallback, with suitable alt text and dimensions.