Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

background-position

Where the background image is placed inside the block.

Syntax

background-position: x y;

Values

ParameterTypeDescription
center | top | right | bottom | leftkeywordKeywords; one or two of them: `right bottom`.
x ylengthOffsets from the top left corner: `20px 10px`, `30% 50%`.

Examples

The same picture cropped from the left, the center and the right:

<style>
  div {
    display: inline-block;
    width: 120px; height: 120px;
    border: 1px solid gray;
    background: url(/media/photo-400x250.jpg) no-repeat;
    background-size: auto 120px;
  }
</style>
 
<div style="background-position: left;"></div>
<div style="background-position: center;"></div>
<div style="background-position: right;"></div>

Notes

With background-size: cover the position decides which part of the photo stays visible — for a portrait, center top keeps the face.

See also

Related recipes

In the tutorial

  • Backgrounds and borders — Background images, their repeat, size and position, border styles, rounded corners and outline.

Thanks for reading!

Donate to the site — we work hard for you.