max-width
Stops images from overflowing their container.
Responsive images keep media sharp, fast and correctly cropped across screen sizes and device densities.
.photo {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
}
Responsive mental model
An image can break a layout by overflowing, loading too heavy or cropping the important subject badly.
Basic responsive image CSS starts with max-width: 100% and height: auto. More advanced work uses srcset, sizes and picture so the browser can choose the right file.
High-end design also considers art direction. Sometimes the mobile crop should be different because the subject needs a different frame.
Stops images from overflowing their container.
Reserves predictable media space.
Controls how an image fills a fixed frame.
Lets the browser choose an efficient image source.
Visual model
The layout reserves stable space.
The image fills the crop without distortion.
The browser can pick the right file.
Important subjects stay visible.
Good CSS versus fragile CSS
.photo {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
border-radius: 1rem;
}
.photo {
width: 900px;
height: 220px;
object-fit: fill;
}
Rules of thumb
Images should not be wider than their container.
Do not force width and height without object-fit or natural ratio care.
aspect-ratio prevents layout jumps before images load.
Large desktop images should not be the only option for mobile.
object-position can keep the subject in view.
Responsive media still needs semantic accessibility.
Production thinking
Images often create the first premium feeling of a page, but they also create many performance and layout problems when handled casually.
Alt text belongs to the HTML image, not CSS. Cropping should not remove critical visual information.
Combine CSS framing with real generated image sizes. A beautiful crop still needs optimized files.
Proper image markup, dimensions and descriptive alt text help image understanding and page quality.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, resize the lab idea mentally and explain what should change.
Senior audit upgrade
CSS can make images fluid and cropped. HTML handles srcset, sizes and picture so the browser can download the right resource.
Use srcset, sizes and picture for responsive file selection and art direction.
Use max-width, aspect-ratio, object-fit and layout sizing for display behavior.
Alt text belongs in HTML and must not be treated as a CSS concern.