Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

The `<picture>` Element and Responsive | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 42 of 55

·HTML

The `<picture>` Element and Responsive Images

9 min

Course progress76%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Using `<picture>` for art direction and responsive image delivery
  • Combining `<source>` elements with media queries and format specifications
  • Responsive images with `srcset` and `sizes` attributes
  • Fallback to `<img>` for browsers that don’t support `<picture>`
  • Performance considerations and testing across devices

The <picture> Element – Art Direction & Responsive Images

<picture> lets you serve different images based on media queries, pixel density, or format support.

<picture>
  <source media='(min-width: 800px)' srcset='hero-large.webp' type='image/webp' />
  <source media='(min-width: 800px)' srcset='hero-large.jpg' type='image/jpeg' />
  <source srcset='hero-medium.webp' type='image/webp' />
  <img src='hero-medium.jpg' alt='Hero illustration' loading='lazy' />
</picture>

Use cases

  • Art direction – Provide a different crop or composition for large screens.
  • Format fallback – Serve WebP when supported, otherwise JPEG.
  • Pixel‑density – Combine with srcset (1x, 2x) for retina displays.
  • Conditional loading – Serve a mobile‑optimized image when the viewport is narrow.

Performance notes

  • Always include a fallback <img> inside <picture> for browsers that don’t support the element.
  • Pair <picture> with lazy loading (loading='lazy') for off‑screen images.
  • Keep the total number of <source> elements reasonable; too many can increase download size.

Quick checklist for <picture>

  1. Fallback <img> present with descriptive alt? ✅
  2. type attributes used for modern formats (image/webp)? ✅
  3. Media queries reflect realistic breakpoints? ✅
  4. loading='lazy' added for non‑above‑the‑fold images? ✅
  5. Tested in browsers without <picture> support (fallback works)? ✅

Tip: Use the Chrome DevTools Network panel to verify that the correct source is selected for the current viewport.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
Previous lessonMicrodata & Structured Data – Schema.orgContinue to lesson 43The `<dialog>` Element – Native Modal DialogsBack to HTML Course curriculum