When to Use w vs x Descriptors
You'll learn when to choose width descriptors versus density descriptors for your responsive images.
The Core Decision
When using srcset, you have two ways to describe your image variants: w descriptors (like 800w) or x descriptors (like 2x). Choosing between them depends on whether your image's display size changes with the viewport or stays fixed.
Think of It Like This
Imagine you're giving directions to a driver:
wdescriptors are like saying "use the highway or local roads depending on traffic and where you're going" — the browser decides based on contextxdescriptors are like saying "always take Route 2" — you're specifying exactly which road for which situation
When to Use w Descriptors
Use width descriptors when your image is responsive — it scales with the viewport or container:
<img srcset="small.jpg 400w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 100vw, 50vw"
src="medium.jpg" alt="Hero image">
The browser picks the best file based on viewport size, device pixel ratio, and your sizes hint. This is your go-to choice for hero images, content images, and most responsive layouts.
When to Use x Descriptors
Use density descriptors when your image has a fixed display size regardless of viewport:
<img srcset="icon.png 1x, icon@2x.png 2x"
width="48" height="48"
src="icon.png" alt="Settings icon">
Perfect for icons, logos, and UI elements that stay the same pixel size — the browser only considers screen density.
Key Takeaway: Use w descriptors with sizes for responsive images that scale; use x descriptors for fixed-size images where only screen density matters.