YI
Back to Blog

Responsive Images Guide: srcset, sizes, and Best Practices 2025

Your Image Resizer Team
7 min read
Share:

Responsive Images Guide: srcset, sizes, and Best Practices 2025


Responsive images are essential for modern web development. Serving appropriately-sized images to different devices improves performance, saves bandwidth, and enhances user experience.


Why Responsive Images Matter


The Problem


Traditional approach serves same image to all devices:

  • Desktop gets 2000px wide image
  • Mobile phone downloads same 2000px image
  • Wastes bandwidth and slows loading
  • Poor mobile experience

  • The Solution


    Responsive images serve different sizes based on:

  • Device screen size
  • Device pixel density
  • Viewport width
  • Layout requirements

  • Benefits:

  • 60-80% faster mobile loading
  • Better Core Web Vitals scores
  • Improved SEO rankings
  • Enhanced user experience

  • HTML Picture Element


    Basic Syntax


    <picture>

    <source srcset="image-large.webp" media="(min-width: 1200px)" type="image/webp">

    <source srcset="image-medium.webp" media="(min-width: 768px)" type="image/webp">

    <source srcset="image-small.webp" type="image/webp">

    <img src="image-fallback.jpg" alt="Description">

    </picture>


    The srcset Attribute


    Device Pixel Ratio Descriptors


    <img src="image-1x.jpg"

    srcset="image-1x.jpg 1x,

    image-2x.jpg 2x,

    image-3x.jpg 3x"

    alt="Description">


    Use Case: Fixed-size images (logos, icons) on different pixel densities


    Width Descriptors


    <img src="image-800w.jpg"

    srcset="image-400w.jpg 400w,

    image-800w.jpg 800w,

    image-1200w.jpg 1200w,

    image-1600w.jpg 1600w"

    sizes="(max-width: 600px) 100vw,

    (max-width: 1200px) 50vw,

    33vw"

    alt="Description">


    Use Case: Fluid-width images that scale with layout


    The sizes Attribute


    Defining Sizes


    The sizes attribute tells the browser how much space the image will take at different viewport widths:


    sizes="(max-width: 600px) 100vw,

    (max-width: 1200px) 50vw,

    33vw"


    Translation:

  • On screens up to 600px: image is 100% viewport width
  • On screens 601-1200px: image is 50% viewport width
  • On screens 1200px+: image is 33% viewport width

  • Browser Selection Algorithm


    1. Browser checks viewport width

    2. Evaluates sizes attribute

    3. Calculates required image width

    4. Selects appropriate image from srcset

    5. Downloads optimal image


    Creating Responsive Image Sets


    Recommended Breakpoints


    Mobile First Approach:

  • 400w: Small phones (portrait)
  • 600w: Large phones (portrait)
  • 800w: Tablets (portrait), small desktops
  • 1200w: Tablets (landscape), medium desktops
  • 1600w: Large desktops
  • 2000w: Extra large screens

  • Density Variations:

    For each breakpoint, consider:

  • 1x: Standard displays
  • 2x: Retina/HiDPI displays
  • 3x: Ultra high-density (rare)

  • Image Generation Workflow


    1. Start with Highest Quality

  • Original high-res image
  • Uncompressed or lossless format

  • 2. Generate All Sizes

  • Use automation tools
  • Maintain aspect ratio
  • Apply appropriate compression

  • 3. Optimize Each Size

  • Format conversion (WebP, AVIF)
  • Quality optimization per size
  • Metadata removal

  • Picture Element Advanced Usage


    Art Direction


    Serve different crops for different layouts:


    <picture>

    <source media="(min-width: 1200px)"

    srcset="hero-wide.jpg">

    <source media="(min-width: 768px)"

    srcset="hero-medium.jpg">

    <img src="hero-narrow.jpg"

    alt="Hero image">

    </picture>


    Use Case:

  • Desktop: Wide landscape crop
  • Tablet: Moderate crop
  • Mobile: Portrait-oriented crop

  • Format Selection


    Serve modern formats with fallbacks:


    <picture>

    <source type="image/avif"

    srcset="image.avif">

    <source type="image/webp"

    srcset="image.webp">

    <img src="image.jpg"

    alt="Description">

    </picture>


    Browser automatically selects first supported format.


    Performance Optimization


    Lazy Loading


    Defer off-screen image loading:


    <img src="image.jpg"

    srcset="..."

    sizes="..."

    loading="lazy"

    alt="Description">


    Benefits:

  • Faster initial page load
  • Reduced bandwidth usage
  • Better Core Web Vitals

  • Prioritize Above-the-Fold


    For critical images:


    <img src="hero.jpg"

    srcset="..."

    sizes="..."

    loading="eager"

    fetchpriority="high"

    alt="Hero">


    Decode Hint


    <img src="image.jpg"

    decoding="async"

    alt="Description">


    Options:

  • async: Decode in background
  • sync: Block rendering until decoded
  • auto: Browser decides

  • Implementation Strategies


    Manual Implementation


    Pros:

  • Full control
  • Custom breakpoints
  • Optimized per image

  • Cons:

  • Time-consuming
  • Maintenance overhead
  • Easy to make mistakes

  • Automated Solutions


    Build Tools:

  • webpack image optimization
  • Gatsby Image
  • Next.js Image component

  • CMS Plugins:

  • WordPress responsive images
  • Drupal image styles

  • Image CDNs:

  • Cloudinary
  • imgix
  • Fastly Image Optimizer

  • Framework-Specific Solutions


    Next.js Image Component


    import Image from "next/image";


    <Image

    src="/image.jpg"

    width={1200}

    height={800}

    sizes="(max-width: 768px) 100vw, 50vw"

    alt="Description"

    />


    Features:

  • Automatic optimization
  • Lazy loading by default
  • Format conversion
  • Responsive by default

  • Testing Responsive Images


    Browser DevTools


    1. Open DevTools Network tab

    2. Resize viewport

    3. Reload page

    4. Check which image loaded


    Validation:

  • Correct size loaded
  • Appropriate format
  • No wasted bandwidth

  • Automated Testing


    Tools:

  • Lighthouse CI
  • WebPageTest
  • responsive-image-linter

  • Check for:

  • Properly sized images
  • Modern format usage
  • Lazy loading implementation

  • Common Mistakes to Avoid


    Mistake 1: Too Few Breakpoints

    Problem: Large gaps between sizes

    Solution: Use at least 4-6 breakpoints


    Mistake 2: Incorrect sizes Attribute

    Problem: Browser downloads wrong size

    Solution: Accurately match layout at each breakpoint


    Mistake 3: Missing Fallback

    Problem: No image in older browsers

    Solution: Always include src attribute


    Mistake 4: Over-Engineering

    Problem: Too many sizes, diminishing returns

    Solution: Balance optimization vs maintenance


    Mistake 5: Ignoring Art Direction

    Problem: Important content cropped on mobile

    Solution: Use picture element for different crops


    Best Practices Checklist


    βœ“ Use srcset for fluid images

    βœ“ Include sizes attribute

    βœ“ Implement lazy loading

    βœ“ Provide WebP/AVIF formats

    βœ“ Include JPEG/PNG fallbacks

    βœ“ Test on real devices

    βœ“ Monitor bandwidth savings

    βœ“ Automate image generation

    βœ“ Use art direction when needed

    βœ“ Optimize for Core Web Vitals


    Real-World Example


    Complete responsive image implementation:


    <picture>

    <!-- AVIF for modern browsers -->

    <source type="image/avif"

    srcset="/images/hero-400.avif 400w,

    /images/hero-800.avif 800w,

    /images/hero-1200.avif 1200w,

    /images/hero-1600.avif 1600w"

    sizes="(max-width: 600px) 100vw,

    (max-width: 1200px) 80vw,

    1200px">


    <!-- WebP fallback -->

    <source type="image/webp"

    srcset="/images/hero-400.webp 400w,

    /images/hero-800.webp 800w,

    /images/hero-1200.webp 1200w,

    /images/hero-1600.webp 1600w"

    sizes="(max-width: 600px) 100vw,

    (max-width: 1200px) 80vw,

    1200px">


    <!-- JPEG ultimate fallback -->

    <img src="/images/hero-800.jpg"

    srcset="/images/hero-400.jpg 400w,

    /images/hero-800.jpg 800w,

    /images/hero-1200.jpg 1200w,

    /images/hero-1600.jpg 1600w"

    sizes="(max-width: 600px) 100vw,

    (max-width: 1200px) 80vw,

    1200px"

    alt="Hero image description"

    loading="eager"

    fetchpriority="high"

    width="1200"

    height="800">

    </picture>


    Measuring Success


    Key Metrics


    Bandwidth Savings:

  • Compare before/after
  • Aim for 50-70% reduction on mobile

  • Load Time Improvement:

  • Measure LCP (Largest Contentful Paint)
  • Target <2.5 seconds

  • User Experience:

  • Bounce rate reduction
  • Increased engagement
  • Better conversion rates

  • Conclusion


    Responsive images are no longer optional - they are essential for modern web performance. By implementing srcset, sizes, and picture elements correctly, you can dramatically improve load times, save bandwidth, and provide better experiences across all devices.


    Get Started


    Use Your Image Resizer to automatically generate all the image sizes you need for responsive implementation. Our batch processing creates optimized images at multiple breakpoints in seconds.

    Share this article:

    Ready to optimize your images?

    Try our free image resizer tool and see the difference

    Get Started Free