picture
The wrapper for multiple image source options.
Learn Picture Element with practical HTML examples for navigation, images, alt text, media behavior, metadata, accessibility, SEO and live practice.
HTML links and media
The picture element is used for art direction and format choice. It wraps source elements and a fallback img element.
Use picture when you need a different crop on mobile, a modern format such as AVIF or WebP with fallback, or a source that changes by media condition.
Do not use picture for every image. For simple resolution switching, img with srcset and sizes may be enough.
The wrapper for multiple image source options.
Defines a candidate source with media or type conditions.
Applies the source only when the media query matches.
The real image element that supplies alt text and fallback behavior.
Syntax and structure
Source elements provide options, but the img element supplies alt text, dimensions and the fallback source.
<picture> <source media="(max-width: 700px)" srcset="/assets/img/course-mobile.webp"> <source type="image/avif" srcset="/assets/img/course.avif"> <img src="/assets/img/course.webp" alt="Student dashboard on a laptop screen" width="960" height="540" > </picture>
<picture> <source srcset="mobile.webp"> <source srcset="desktop.webp"> </picture> <picture><img src="hero.jpg"></picture>
HTML quick reference
Use these patterns when you need the syntax quickly. Each example has its own anchor, so search engines and readers can land directly on the exact pattern instead of only at the top of the lesson.
A clean version of the markup from this lesson. Use it when you need the correct HTML shape quickly.
<picture> <source media="(max-width: 700px)" srcset="/assets/img/course-mobile.webp"> <source type="image/avif" srcset="/assets/img/course.avif"> <img src="/assets/img/course.webp" alt="Student dashboard on a laptop screen" width="960" height="540" > </picture>
Meaningful markup that stays understandable before CSS and JavaScript are added.
The starting point from the practice lab. Change the HTML first, then use CSS only for presentation.
<main class="demo-card"> <p class="eyebrow">Picture</p> <h1>Different sources, one image meaning.</h1> <picture> <source media="(max-width: 700px)" srcset="mobile-course.webp"> <img src="desktop-course.webp" alt="Course dashboard preview" width="800" height="450"> </picture> <p>The img fallback still carries the alt text.</p> </main> <style> body { margin: 0; min-height: 100vh; display: grid; place-items: center; font-family: Inter, system-ui, sans-serif; background: #07111f; color: white; } .demo-card { width: min(780px, calc(100% - 32px)); padding: 34px; border-radius: 24px; background: #101a2d; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3); } .eyebrow { color: #8cffc1; font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; } h1 { margin: 10px 0 16px; font-size: clamp(34px, 7vw, 58px); line-height: 1; } p, figcaption { color: #cfd8e6; line-height: 1.7; } nav { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0; } a { color: #8cffc1; font-weight: 800; } nav a { border: 1px solid rgba(140, 255, 193, 0.28); border-radius: 999px; padding: 10px 14px; text-decoration: none; } img { display: block; max-width: 100%; height: auto; border-radius: 18px; } .result-note { margin-top: 14px; border: 1px solid rgba(140, 255, 193, 0.28); border-radius: 16px; padding: 12px 14px; background: rgba(140, 255, 193, 0.1); } .demo-highlight { outline: 3px solid rgba(140, 255, 193, 0.55); outline-offset: 4px; } </style>
A complete practice snippet that shows how the HTML behaves in context.
A weak pattern from the lesson. Use it as a warning sign when reviewing real pages.
<picture> <source srcset="mobile.webp"> <source srcset="desktop.webp"> </picture> <picture><img src="hero.jpg"></picture>
A recognizable mistake you can search for and refactor.
Rules that matter
Clickable and visual HTML affects how people move, scan, trust and share a page. The details are small, but the user experience impact is large.
The img element is required for fallback, alt text and dimensions.
Use picture when the image itself should change, not only shrink.
The browser uses the first matching source.
Source elements do not replace alt text.
Mobile art direction should preserve the subject.
Use plain img when one image source is enough.
Production thinking
This matters because responsive design is not only layout. Sometimes the image crop must change so the subject still looks premium on every screen.
The accessible meaning comes from the fallback img alt text, no matter which source the browser chooses.
Picture is powerful for high-end responsive media, but it needs disciplined image generation and QA across viewports.
Search engines can understand the fallback img. Use descriptive alt text and surrounding content.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.