Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

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.

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

Why does background-size: cover cut off the sides or top of my image? I expected the whole image to shrink to fit.

Geez

cover has a different goal: fill the entire background positioning area without leaving uncovered space. It scales the image proportionally until both dimensions cover that area. If the image and area have different proportions, the image will be too large along at least one dimension, and the overflow is cropped. [S1]

For example, assume a 1200 × 900 image and a 600 × 300 area. To cover the area, the image scales to 600 × 450: its width fits, but its height exceeds the area by 150 pixels. With a centered position, that excess is divided between the top and bottom. This is an illustrative calculation, not a measurement of your image.

.hero {
  background-image: url("[image-path]");
  background-size: cover;
}

Think of it this way: cover fills the box first; cropping is the tradeoff when the proportions differ.

Follow-up question

Can you show that as a simple diagram? How can I tell which direction will crop?

Geez

Compare the proportions of the image with the proportions of the area. In the example above, the scaled image is taller than the area, so the top and bottom cannot all remain visible at once:

Scaled image: 600 × 450
┌──────────────────────────┐
│  75px outside the area   │  cropped
├──────────────────────────┤
│                          │
│     visible area         │  600 × 300
│                          │
├──────────────────────────┤
│  75px outside the area   │  cropped
└──────────────────────────┘

If instead the scaled image extends beyond the area's width, the crop is on the left and right. The amount and direction depend on the image dimensions, the area dimensions, and its position. The positioning area depends on the background positioning rules; it is the padding box by default, while fixed attachment uses the viewport. [S1]

To check your own case, inspect the element's dimensions and the source image's dimensions, then compare their proportions. The diagram is an illustration; your layout's measurements determine the actual crop.

Follow-up question

How do I move the visible part so the subject stays in frame?

Geez

Set background-position to change which portion of the oversized image is visible. The default position is 0% 0%. Percentage positions depend on the size difference between the image and area, so the same percentage does not mean a fixed number of pixels. [S2]

Try a few positions while previewing the actual image:

.hero {
  background-size: cover;
  background-position: center;
}

.hero--alternate {
  background-position: 70% 50%;
}

center is a useful comparison point; the second rule is an example to test, not a promise that it will keep a particular subject visible. If the image and area are the same size along an axis, adjusting the percentage on that axis has no effect because there is no size difference there. [S2] Choose the position based on what you need to keep in view.

Follow-up question

What should I compare if I want less cropping, and what is a practical way to test it?

Geez

First decide whether filling the whole area or showing the entire image matters more. cover fills the area, but mismatched proportions can mean cropping. [S1] If you want to keep more of the image, consider changing the element's dimensions or choosing a layout that does not require the background to fill every edge; preview the result rather than assuming it will fit a particular way.

A simple test is to change one setting at a time: keep the same image and element size, preview cover, then adjust background-position and compare what remains visible. Record the image dimensions, element dimensions, and position for each version so you can reproduce the preferred result. If the subject is near an edge, check that edge at the actual display size too; a position that works in one area may not suit another.

The core tradeoff is straightforward: cover fills the area, and mismatched proportions mean cropping; positioning controls which part of an oversized image you see. [S1][S2]

A practical checklist

  • Compare the image's proportions with the background area's proportions.

  • Confirm which element provides the background positioning area.

  • Preview cover and note which edge or edges are cropped.

  • Adjust background-position and 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?

No. It changes which portion is visible; it does not change the cover scaling rule. Cropping can remain when the image and area have different proportions. [S1][S2]

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.

  1. [S1] MDN: CSS background-size and the cover value
    developer.mozilla.org · Checked
  2. [S2] MDN: CSS background-position and image placement
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work