Prompt
How do I make images responsive for different screen sizes?
Latest observation
Nov 13, 2026
OpenAI APIWeb search: off
To make images responsive, the goal is for them to scale nicely across different screen sizes without overflowing or becoming distorted.
1) Use CSS to scale the image
The most common approach is:
img {
max-width: 100%;
height: auto;
}
What this does:
max-width: 100%keeps the image from being wider than its containerheight: autopreserves the image’s aspect ratio
2) Put the image inside a flexible container
If the parent container is responsive, the image will be too:
<div class="image-wrapper">
<img src="photo.jpg" alt="Example image">
</div>
.image-wrapper {
width: 100%;
max-width: 800px;
}
3) Use srcset and sizes for better performance
This lets the browser choose the best image size for the device.
<img
src="small.jpg"
srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 100vw, 800px"
alt="Responsive image">
Why this helps:
- Smaller screens download smaller images
- Faster loading
- Better image quality on large screens
4) Use CSS object-fit for fixed-size image boxes
If the image needs to fill a set area:
img {
width: 100%;
height: 300px;
object-fit: cover;
}
Notes:
coverfills the box and may crop the imagecontainshows the whole image but may leave empty space
5) Use background images when appropriate
If the image is decorative, use CSS background images:
.hero {
background-image: url("hero.jpg");
background-size: cover;
background-position: center;
}
Best practice
For most content images, use:
img {
max-width: 100%;
height: auto;
}
And for performance, add srcset and sizes when possible.
If you want, I can also show you how to make images responsive in Bootstrap, React, or with Tailwind CSS.