Why does background-size: cover crop part of my background image?
Quick answer
background-size: cover scales a background image proportionally until it covers the whole positioning area. If the image and area have different proportions, the scaled image extends beyond one or more edges, so some of it is cropped. Adjust background-position to choose which part remains visible, or change the layout if showing the entire image matters more than filling the area.
The question, the details, the next step.
A practical checklist
Compare the image's proportions with the background area's proportions.
Confirm which element provides the background positioning area.
Preview
coverand note which edge or edges are cropped.Adjust
background-positionand check that the important subject stays visible.Test the chosen settings at the actual element size and record them.
A few more useful answers
Does `background-position: center` prevent cropping?
Why does changing the position seem to do nothing?
If the image and positioning area are the same size along the axis you changed, a percentage position on that axis has no effect because their size difference is zero. [S2]
Can I use `cover` and still show every part of the image?
Not when covering the whole area requires the image to extend beyond it. Decide whether filling the area or showing the entire image matters more, then adjust the layout to suit that priority. [S1]
Sources
References used for this guide.
- [S1] MDN: CSS background-size and the cover value developer.mozilla.org · Checked
- [S2] MDN: CSS background-position and image placement developer.mozilla.org · Checked
