Imagine opening this page on a slow phone connection. The media should still be worth the wait and have a sensible fallback.
What You Need to Know
Picture can supply a different crop for narrow and wide screens. That is art direction: choosing which part of the image communicates the idea best, rather than simply shrinking one picture.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<picture>
<source media="(max-width: 600px)" srcset="images/portrait-crop.jpg">
<img src="images/group-photo.jpg" alt="Students presenting their robotics project" width="1000" height="600">
</picture>
Let’s Read the Code
- <picture>: The picture can offer alternate crops or formats to the browser.
- <source>: A source points to a media file or image choice with a type or other condition.
- srcset: Srcset offers image candidates for different displays or layout sizes.
- src: Src identifies a resource path for images, frames, or media.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
The paths shown here refer to files in your own example project. Put real images and recordings in those locations before expecting them to load.
Which picture loads? With width descriptors, sizes describes the expected display width and srcset offers candidates. The browser can also consider screen density and network conditions. Inspect the selected source instead of assuming every screen receives the same file.
Your Turn
Try changing one file path or attribute. Notice whether the browser falls back to another source or shows missing content.
Common Beginner Mistakes
- Leaving out real media files or understandable text alternatives.
- Always check keyboard access, readable alternatives, and any missing files; a perfect player layout does not guarantee accessible content.
Key Takeaways
- Picture can supply a different crop for narrow and wide screens.
- <picture>: The picture can offer alternate crops or formats to the browser.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.