Mrs. Yanti’s signboard in Mr. Karim’s frame: set background-size, -position and -repeat, the browser paints the image and again faintly outside the frame, so…
Why it matters
Almost every hero, banner and card uses cover or contain. Pick wrong and the image is squashed, repeats on its own, or loses its important part. And a background is decoration: a meaningful image needs an <img> with alt.
The key idea
cover takes the larger scale, contain the smaller
Common mistakes
The background image looks squashed or repeats by itself The defaults are background-size: auto (natural size) and background-repeat: repeat, so a small image repeats. Set cover/contain (or 100% auto) and no-repeat. Squashing comes from forcing both sides, e.g. 100% 100%.
The important part of the photo ends up out of frame That is cover cropping the wrong side. Set background-position (e.g. 80% center or 50% 20%) so the image’s focus stays in view.
Screen readers say nothing although the image matters A background has no alt and screen readers skip it. A meaningful image uses <img alt="…"> with object-fit: cover.
Try it in this playground
Compare cover and contain Watch the scale line: max vs min of the same two numbers. The paint outside the frame shows what is cut.
With cover, change background-position The visible part shifts; the cut moves to the other side.
Make the frame tall and narrow Now cover crops left and right, not top and bottom: the winning scale switches sides.
Use a small image with repeat, space or round Count the tiles. space spreads whole tiles, round resizes them to fit.