Course contentsShow
← Web Development
Lesson 417 of 2,9827. Responsive DesignFree lesson

Width Descriptors (w) in srcset

Declaring image widths with the w descriptor to let browsers choose based on viewport and density.

Width Descriptors (w) in srcset

What you'll learn: How to tell the browser exactly how wide each image file is so it can pick the perfect one for any screen.

The Problem with x Descriptors

In the last lesson, you learned about srcset with pixel density descriptors (1x, 2x). But those assume all screens at a given density need the same image size. What if a mobile user with a high-density screen has a small viewport? They'd download a massive file they don't need.

What Are Width Descriptors?

Width descriptors (w) let you declare the actual pixel width of each image file. Instead of saying "this is for 2x screens," you say "this image is 800 pixels wide."

<img 
  src="photo.jpg" 
  srcset="photo-400.jpg 400w,
          photo-800.jpg 800w,
          photo-1200.jpg 1200w"
  alt="Landscape">

Here, 400w means "this file is 400 pixels wide," 800w means 800 pixels, and so on.

How the Browser Decides

The browser combines three pieces of information:

  1. Viewport width (how wide is the screen?)
  2. Device pixel ratio (standard or high-density display?)
  3. Image widths (from your w descriptors)

It picks the smallest file that will still look sharp—saving bandwidth on small screens while delivering quality on large displays.

Think of It Like Shopping

It's like a clothing store where you tell the salesperson "I have sizes Small (400), Medium (800), and Large (1200)." The customer (browser) looks at their measurements (viewport + density) and picks the best fit. You're giving options, not forcing a choice.

Key Takeaway: Width descriptors (w) tell browsers the actual pixel width of each image file, letting them intelligently choose based on both viewport size and screen density—more efficient than density descriptors alone.