Common srcset Patterns
You'll learn practical srcset patterns for three common layout scenarios: full-width heroes, grid items, and sidebar images.
Now that you understand how srcset and sizes work together, let's apply them to real-world situations. Different image layouts need different strategies because they occupy different amounts of screen space.
Full-Width Hero Images
Heroes span the entire viewport width, so they need the largest images:
<img src="hero-800.jpg"
srcset="hero-400.jpg 400w,
hero-800.jpg 800w,
hero-1200.jpg 1200w,
hero-1600.jpg 1600w,
hero-2400.jpg 2400w"
sizes="100vw"
alt="Mountain landscape at sunset">
The sizes="100vw" tells the browser this image always fills 100% of the viewport width, so it can pick appropriately large files.
Grid Item Images
Grid items typically occupy a fraction of the screen, often changing at breakpoints:
<img src="product-400.jpg"
srcset="product-400.jpg 400w,
product-800.jpg 800w,
product-1200.jpg 1200w"
sizes="(min-width: 1024px) 33vw,
(min-width: 640px) 50vw,
100vw"
alt="Blue ceramic mug">
This says: on large screens use 33% width (three columns), on medium screens 50% (two columns), on small screens 100% (one column).
Sidebar Images
Sidebar images are constrained by a maximum width and typically don't scale with the viewport:
<img src="author-200.jpg"
srcset="author-200.jpg 200w,
author-400.jpg 400w,
author-600.jpg 600w"
sizes="(min-width: 1024px) 300px,
100vw"
alt="Author headshot">
Above 1024px, the sidebar is fixed at 300px wide. Below that, it fills the screen.
Key Takeaway: Match your sizes attribute to your actual CSS layout—full-width images need 100vw, grid items need fractional viewport widths with breakpoints, and sidebars often use fixed pixel values.