Pixel Density Descriptors (x) for Retina Displays
You'll learn how to serve sharper images to high-resolution screens using x descriptors in srcset.
The Problem with High-DPI Screens
Modern devices like Retina displays pack multiple physical pixels into each CSS pixel. A standard image that looks fine on older screens appears blurry on these high-density displays because it's being stretched.
Think of it like printing a small photo on a large poster—the image gets fuzzy. The solution? Provide higher-resolution versions of the same image for devices that can display them.
How Pixel Density Descriptors Work
Instead of width descriptors (w), you use the x descriptor to tell the browser which image matches which pixel density ratio:
<img src="photo.jpg"
srcset="photo.jpg 1x,
photo@2x.jpg 2x,
photo@3x.jpg 3x"
alt="A crisp photo">
The 1x represents standard screens (1 device pixel = 1 CSS pixel). The 2x is for displays where 1 CSS pixel equals 4 physical pixels (2×2), and 3x is for even denser screens (3×3 = 9 physical pixels per CSS pixel).
When to Use x Descriptors
Use x descriptors when:
- The image displays at a fixed size regardless of viewport width
- You want simple device-pixel-ratio-based switching
- Icons, logos, or UI elements need to stay sharp on all screens
This approach is simpler than width descriptors but less flexible—it doesn't adapt to different image display sizes, only to screen density.
Key Takeaway: Use 1x, 2x, and 3x descriptors in srcset to provide appropriately sharp images for standard, Retina, and ultra-high-DPI displays when your image size is fixed across viewports.