On this page
Media & Responsive Images
Prev: Accessible Forms & Validation | Up: tutorials | Next: Native Interactive Patterns
Rel: Tables & Media, Box Model & Sizing, Reflow, Repaint & Performance
Ref: MDN Web Docs — Responsive Images
Tags: #public #web #html #tutorials #media
Contents
Resolution Switching (srcset & sizes)
Provide width descriptors (w) in srcset and tell the browser the rendered layout width in sizes so it downloads only the smallest sharp asset needed.
<img
src="hero-800.jpg"
srcset="hero-400.jpg 400w, hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="(max-width: 600px) 100vw, 50vw"
alt="Mountain sunrise"
width="1600"
height="900"
decoding="async"
/>
Format Fallback & Art Direction (<picture>)
<picture> lets you serve modern formats (AVIF/WebP) or alternate crops per media query while keeping <img> as the fallback and accessibility anchor.
<picture>
<source type="image/avif" srcset="photo.avif" />
<source type="image/webp" srcset="photo.webp" />
<img src="photo.jpg" alt="Product showcase" width="800" height="600" loading="lazy" />
</picture>
Linked from
Related notes
- tuts/html/elements/tables_and_media Linked here; links to this page; shared tags: #html, #media, #web
- tuts/html/tutorials Linked here; links to this page; shared tags: #html, #tutorials, #web
- tuts/html/tutorials/accessible_forms_and_validation Linked here; links to this page; shared tags: #html, #tutorials, #web
- tuts/html/tutorials/native_interactive_patterns Linked here; links to this page; shared tags: #html, #tutorials, #web
- tuts/css/properties/box_model_and_sizing Linked here; shared tags: #web
- tuts/web/rendering/reflow_repaint_and_performance Linked here; shared tags: #web
- tuts/html/elements/media shared tags: #html, #media, #web
- tuts/html/elements/media/canvas shared tags: #html, #media, #web
- tuts/html/elements/media/figure shared tags: #html, #media, #web
- tuts/html/elements/media/img shared tags: #html, #media, #web