consolelog.tools logo

Responsive Image Generator

Generate responsive image code with srcset, sizes, and picture elements

Configuration

Image Sizes

Selected Sizes (3)
640w, 1024w, 1920w

Generated Code

<img
  src="/images/hero.jpg"
  srcset="/images/hero-640w.jpg 640w, /images/hero-1024w.jpg 1024w, /images/hero-1920w.jpg 1920w"
  sizes="(min-width: 640px) 1024px, (min-width: 1024px) 1024px"
  alt="Descriptive alt text"
  loading="lazy"
  decoding="async"
/>

Usage Example

srcset: Defines different image sources and their widths

The browser selects the most appropriate image based on screen size and pixel density.

sizes: Tells the browser how wide the image will be at different breakpoints

This helps the browser choose the right image even before downloading it.

Responsive Image CSS

/* Responsive Image Styles */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

picture {
  display: block;
}

picture img {
  width: 100%;
  height: auto;
}

/* Aspect ratio containers */
.aspect-16-9 {
  aspect-ratio: 16 / 9;
}

.aspect-4-3 {
  aspect-ratio: 4 / 3;
}

.aspect-1-1 {
  aspect-ratio: 1 / 1;
}

/* Object fit utilities */
.object-cover {
  object-fit: cover;
}

.object-contain {
  object-fit: contain;
}

Best Practices

  • Use 5-8 image sizes to cover common device widths
  • Always provide meaningful alt text for accessibility
  • Use lazy loading for images below the fold
  • Serve modern formats (AVIF, WebP) with fallbacks
  • Set width and height attributes to prevent layout shift

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Frequently Asked Questions - Responsive Image Generator