liveBook · Manning

Background-position

As explained in CSS in Depth, Second Edition

The CSS background-position property specifies the position of a background image within an element.

background-position specifies where a background image begins within an element. When it receives two values, read them as a Cartesian coordinate: horizontal first, then vertical. section 1.4.2 section 13.1

Use the value order deliberately:

  • background-position: 25% 75% places the horizontal value first and the vertical value second. section 1.4.2
  • Treat two-value positioning like x, y measurements, unlike four-sided properties such as padding, which use a different order. section 1.4.2
  • Keep background-position separate when combining several background settings, because the background shorthand resets unspecified properties to their initial values. section 13.1

Read the coordinates like a grid

For background-position: 25% 75%, 25% controls the image’s horizontal position and 75% controls its vertical position. The same x-then-y reasoning appears in box-shadow: 10px 2px, where the larger first value is horizontal and the second is vertical. section 1.4.2

Listing 1.23 box-shadow specifies x value and then y value
.nav .featured {
  background-color: orange;
  box-shadow: 10px 2px #6f9090;     #1
}

Compare the box-shadow listing to background-position to see the shared x-then-y convention for two measurements. section 1.4.2

How CSS in Depth, Second Edition covers it

How deep it goes
Explains the horizontal-then-vertical rule and its Cartesian rationale, but does not develop positioning edge cases or image-rendering behavior.
Examples
Uses 25% 75% for background positioning and 10px 2px for an analogous box-shadow coordinate example.
What it assumes
Assumes familiarity with CSS properties and background images while reinforcing the distinction between two-value and four-value syntax.
What you can do after
Apply background-position values by reading two measurements as horizontal x followed by vertical y.
How it connects
Connects background-position to background shorthand, background-image, box-shadow, text-shadow, and four-sided padding conventions.

Also explained in

Compare how 2 books explain background-position →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.