Skip to main content
InterviewHubPRO
Section Overview
Q8

Question 8 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

16%
HTML5 & Web APIs (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

How does media embedding work with `<picture>`, `<source>`, and `<img>`?

junior LevelCode ExamplehtmlBasic

In Simple Words: While <img> displays a single image, the <picture> element enables art direction and responsive format selection:

html
<picture>
  <!-- Serve ultra-lightweight AVIF to supporting browsers -->
  <source srcset="hero.avif" type="image/avif" />
  <!-- Fallback to WebP -->
  <source srcset="hero.webp" type="image/webp" />
  <!-- Responsive mobile crop -->
  <source media="(max-width: 600px)" srcset="hero-mobile.jpg" />
  <!-- Default fallback image with responsive srcset and sizes -->
  <img src="hero-desktop.jpg"
       srcset="hero-400.jpg 400w, hero-800.jpg 800w, hero-1200.jpg 1200w"
       sizes="(max-width: 600px) 100vw, 800px"
       alt="Conference keynote presentation"
       loading="lazy"
       width="800"
       height="450" />
</picture>