How do you make a CSS background image responsive?

A responsive CSS background needs a flexible container, an intentional crop rule and a fallback color. Set background-size according to the design: cover fills the box and crops excess edges, while contain keeps the entire image visible and may leave unused space. Choose the behavior before adjusting breakpoints.
The container must also have height. Content, padding, min-height or aspect-ratio can establish it. A background does not contribute intrinsic dimensions to layout, so an empty hero with no height may collapse. Prefer content-driven height when the section contains text because translated copy and larger fonts need room.
.hero {
min-height: clamp(22rem, 65svh, 42rem);
padding: clamp(2rem, 6vw, 6rem);
background-color: #243044;
background-image: url('hero-1600.webp');
background-position: 65% 50%;
background-repeat: no-repeat;
background-size: cover;
}
Use background-position to keep the subject visible as cropping changes. Percentages or position keywords work for a consistent focal point. If a single source cannot keep the subject readable at narrow and wide ratios, switch to an art-directed file in a media query. Decorative backgrounds should not carry information that users need.
Serve an appropriately sized and compressed file. CSS backgrounds do not support the same automatic candidate selection pattern as a straightforward responsive img, although image-set can provide density or format choices where supported. Avoid sending a huge desktop image to every phone. A flat background color should preserve text contrast while the image loads.
Test short and tall viewports, zoomed text and real copy. Check that foreground text never depends on a bright or dark patch that moves under it. Confirm the background does not create horizontal overflow, and inspect transferred bytes on a phone-sized viewport. A responsive crop must remain legible as well as visually balanced.