The Resolution Problem
HAP's Discovery: Prof. Teeters explained it like this: sending a 2000px image to a 320px phone screen is like shipping a refrigerator to someone who ordered a lunchbox! Or worse, sending a tiny 320px image to a 4K monitor is like giving someone a postage stamp to hang on their wall.
Mobile Waste
85% wasted
2MB image β 320px screen
User pays for unused pixels
Slow loading, frustrated users
Desktop Blur
Pixelated
320px image β 1440px display
Stretched and blurry
Unprofessional appearance
One Size Fails All
No Winner
No perfect middle ground
Either too big or too small
Need multiple versions!

HAP's Confession:
The srcset syntax looked like gibberish to me at first! All those 'w' descriptors and sizes calculations seemed impossible. But Prof. Teeters showed me it's just telling the browser: "Here are your options, pick the best one." Once I understood that, everything clicked!
Understanding srcset Width Descriptors
Prof. Teeters taught me that the srcset
attribute gives browsers multiple
image options
using width descriptors. You tell the browser the actual pixel width of each image file, and it
intelligently selects the best one based on the device's screen size and pixel density.
π How Width Descriptors Work
What they mean: "This image file is 300 pixels wide"
Syntax: image.jpg 300w
Why they're powerful: The browser automatically handles pixel density!
A 300w image can serve both a 300px display at 1x density AND a 150px display at 2x density.
π¬ Browser Intelligence
The browser knows:
β’ Viewport size
β’ Device pixel ratio (1x, 2x, 3x)
β’ Network conditions
β’ User preferences
It uses ALL this information to pick the optimal image automatically!
<img srcset="small.jpg 300w,
medium.jpg 600w,
large.jpg 1200w"
src="medium.jpg"
alt="Responsive example">
/* Browser sees: "I have 3 options: a 300px wide file, a 600px wide file, and a 1200px wide file" */
π― Width Descriptor Benefits
- Automatic density handling: No need to create separate 1x, 2x, 3x versions
- Future-proof: Works with any pixel density, even 4x or higher
- Simpler workflow: Just provide different sizes, browser does the math
- Better performance: Browser can optimize based on network speed too
<img srcset="puppy-small.jpg 400w,
puppy-medium.jpg 800w,
puppy-large.jpg 1600w"
src="puppy-medium.jpg"
alt="Cute puppy">
β’ puppy-small.jpg: 45KB file, 400px wide
β’ puppy-medium.jpg: 125KB file, 800px wide
β’ puppy-large.jpg: 380KB file, 1600px wide
β Mobile users get 45KB instead of
380KB!
π Critical rule: Always use 'w' descriptor
β RIGHT:
srcset="small.jpg 300w, large.jpg 600w"
β WRONG:
srcset="small.jpg, large.jpg"
(no descriptors)
Every image in srcset MUST have a width descriptor. The 'w' tells the browser the actual pixel width of that image file.
Mastering the sizes Attribute
The srcset
tells the browser "what image files are
available" but the browser needs to know "how big will the image display on the page?" The
sizes
attribute provides that crucial information. Without it, the browser assumes
100vw (full viewport width).
<img srcset="small.jpg 300w, medium.jpg 600w, large.jpg 1200w"
sizes="(max-width: 320px) 280px,
(max-width: 640px) 100vw,
50vw"
src="medium.jpg"
alt="Example with sizes">
Line 1: Phone Screens
(max-width: 320px) 280px
"On phones β€320px wide, the image displays at 280px"
Line 2: Small Tablets
(max-width: 640px) 100vw
"On screens β€640px, the image fills the viewport"
Line 3: Default Size
50vw
"On larger screens, image takes half the width"
How It Works
β’ Browser checks top to bottom
β’ First match wins
β’ Last value is the default
β’ Browser multiplies by pixel density!
Common sizes Patterns
Full-width Images
Use for: Heroes, banners, edge-to-edge images
Content with Margins
Use for: Blog posts, articles with padding
Sidebar Layouts
Use for: Aside content, author bios
Grid Layouts
Use for: Card grids, galleries
π― The vw Unit Explained
vw = viewport width percentage
100vw
= full viewport width50vw
= half viewport width25vw
= quarter viewport widthcalc(100vw - 2rem)
= full width minus padding
π How Browser Selects Images
Example: On a phone with 360px viewport and 3x pixel density:
- Browser checks
sizes
: image will display at 100vw = 360px - Multiplies by pixel density: 360px Γ 3 = 1080px needed
- Looks at
srcset
: picks smallest image β₯1080px wide - Downloads the 1200w image (if available)
π Common Mistakes to Avoid
- Forgetting sizes entirely β Browser assumes 100vw, often wrong
- Wrong order β Media queries must go smallest to largest
- Using px in conditions β Write
(max-width: 640px)
not just640px
- Over-complicating β Start simple, 2-3 breakpoints usually enough
Putting It All Together
<!-- Blog Post Image -->
<img srcset="blog-400.jpg 400w,
blog-800.jpg 800w,
blog-1200.jpg 1200w,
blog-1600.jpg 1600w"
sizes="(min-width: 840px) 800px,
calc(100vw - 2rem)"
src="blog-800.jpg"
alt="Blog post illustration">
Why this works:
β’ 4 size options cover all devices
β’ Desktop gets fixed 800px (content width)
β’ Mobile gets full width minus padding
β’ Handles all pixel densities automatically
β’ Fallback src for old browsers
<!-- Full-Width Hero -->
<img srcset="hero-640.jpg 640w,
hero-1280.jpg 1280w,
hero-1920.jpg 1920w,
hero-2560.jpg 2560w"
sizes="100vw"
src="hero-1280.jpg"
alt="Hero banner">
Perfect for:
β’ Landing pages
β’ Full-bleed headers
β’ Background images
β’ Automatically serves 2x for retina displays!
<!-- Grid Item -->
<img srcset="product-200.jpg 200w,
product-400.jpg 400w,
product-600.jpg 600w,
product-800.jpg 800w"
sizes="(min-width: 1200px) 25vw,
(min-width: 768px) 50vw,
100vw"
src="product-400.jpg"
alt="Product thumbnail">
Responsive grid magic:
β’ 4 columns on desktop (25vw each)
β’ 2 columns on tablet (50vw each)
β’ 1 column on mobile (100vw)
β’ Browser picks optimal file for each!
π¬ Testing Your Implementation
- Open DevTools Network tab
- Filter by Images
- Resize browser window
- Refresh at different sizes
- Verify correct image loads
- Check file sizes match expectations
- Test on real devices with different pixel densities
π HyBit's Quick Reference
Start Simple
Begin with 3-4 breakpoints: mobile (400w), tablet (800w), desktop (1200w), large (1600w). Always use width descriptors with the 'w' suffix. Default sizes to "100vw" if unsure, then refine.
Remember the Formula
srcset = "Here are my image files and their pixel widths"
sizes = "This is how big it displays on the page"
Browser = "I'll pick the best one considering pixel density and network"
Universal pattern that works
<img srcset="img-400.jpg 400w,
img-800.jpg 800w,
img-1200.jpg 1200w,
img-1600.jpg 1600w"
sizes="(min-width: 1024px) 1024px, 100vw"
src="img-800.jpg"
alt="Description">
This covers 95% of use cases and handles all pixel densities!
Width Descriptors Handle Everything
The beauty of width descriptors: they automatically handle pixel density!
A 1200w image
serves:
β’ 1200px displays at 1x density
β’ 600px displays at 2x density (retina)
β’ 400px displays at 3x density
No need for separate density versions!