What You'll Learn
You'll learn how to serve sharper images to high-resolution displays (like Retina screens) using the x descriptor in srcset for fixed-width images.
The High-DPI Display Problem
Modern devices like iPhones, MacBooks, and many Android phones pack twice (or more) the pixels into the same physical space compared to standard screens. This is called device pixel ratio (DPR). A 2x display means a 100px image actually needs 200 physical pixels to look crisp. Without special handling, your images appear blurry or "soft" on these screens.
Think of it like printing: a low-resolution photo looks fine on screen but fuzzy when printed. High-DPI displays are like print quality on screens.
Using the x Descriptor
When your image has a fixed display size (not responsive width), use the x descriptor to provide different resolutions:
<img
src="photo.jpg"
srcset="photo.jpg 1x,
photo@2x.jpg 2x,
photo@3x.jpg 3x"
alt="Mountain landscape"
width="300">
The x descriptor tells the browser: "Use photo@2x.jpg on 2x displays (Retina), photo@3x.jpg on 3x displays (high-end phones), and photo.jpg on standard 1x displays."
The browser automatically picks the best match based on the device's pixel ratio. You don't need sizes here because the image width is fixed.
When to Use x vs Width Descriptors
- Use
xdescriptors: Fixed-size images (icons, logos, thumbnails with CSS width) - Use width descriptors (
w): Responsive images that scale with viewport
Key Takeaway: The x descriptor in srcset lets you serve higher-resolution images to high-DPI displays automatically, ensuring sharp visuals on Retina and similar screens without manually detecting device capabilities.