CSS background-position-y Property

The background-position-y property specifies the vertical position of an element's background images.

It controls where background images appear along the vertical axis without changing their horizontal positions. The property accepts alignment keywords, lengths, percentages, and offsets from the top or bottom edge. It also supports independent positioning for multiple background image layers.

background-position-y Syntax

selector {
  background-position-y: center;
}

The property accepts vertical alignment keywords, numeric offsets, percentages, and combinations of edge keywords with offsets.

.top-position {
  background-position-y: top;
}
.center-position {
  background-position-y: center;
}
.bottom-position {
  background-position-y: bottom;
}
.pixel-position {
  background-position-y: 25px;
}
.percentage-position {
  background-position-y: 75%;
}
.edge-offset-position {
  background-position-y: bottom 20px;
}
.multiple-positions {
  background-position-y: top, bottom;
}

The property also accepts CSS-wide values such as inherit, initial, revert, revert-layer, and unset.

Property Values

Value Description
top Aligns the top edge of the background image with the top edge of its positioning area.
center Centers the background image vertically within its positioning area.
bottom Aligns the bottom edge of the background image with the bottom edge of its positioning area.
<length> Positions the image vertically using a length such as px, em, or rem.
<percentage> Aligns the specified percentage point of the image with the corresponding point of the positioning area.
top <length-percentage> Positions the image at a specified offset from the top edge.
bottom <length-percentage> Positions the image at a specified offset from the bottom edge.
comma-separated list Specifies vertical positions for multiple background image layers.

The property applies to all elements, is not inherited, and has an initial value of 0%, equivalent to top. Its computed value is a list of vertical positions, and compatible numeric positions can be animated.

Only the vertical component is affected. The horizontal component is controlled separately by background-position-x.

How background-position-y Works

The background-position-y property positions a background image vertically within the background positioning area.

.panel {
  width: 300px;
  height: 180px;
  background-image: url("decoration.png");
  background-repeat: no-repeat;
  background-position-y: bottom;
}

The image is aligned with the bottom edge of the positioning area. Its horizontal position remains controlled by background-position-x, which defaults to 0%.

The Background Positioning Area

By default, the positioning area is the element's padding box. The background-origin property can change this to the border box or content box.

Changing Only the Vertical Position

.decorative-panel {
  background-image: url("decoration.png");
  background-repeat: no-repeat;
  background-position: center top;
  background-position-y: bottom;
}

The final declaration moves the image to the bottom while preserving its centered horizontal position.

Background Positioning Does Not Affect Layout

Moving a background image vertically does not change the position of the element, its text, or its child elements.

The property changes only the placement of background image layers, including CSS-generated gradients.

Vertical Position Keywords

The top, center, and bottom keywords provide three common vertical alignments.

Aligning Top

.top-aligned {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position-y: top;
}

The image's top edge aligns with the top edge of the positioning area.

Centering Vertically

.center-aligned {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position-y: center;
}

The image is centered vertically. Its horizontal position does not change.

Aligning Bottom

.bottom-aligned {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position-y: bottom;
}

The image's bottom edge aligns with the bottom edge of the positioning area.

Equivalent Percentage Values

Keyword Equivalent Value
top 0%
center 50%
bottom 100%

Use keywords when simple alignment is sufficient and exact numeric offsets are unnecessary.

Length Values

Length values position a background image at a specific vertical distance from the top edge of its positioning area.

.pixel-offset {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position-y: 25px;
}

The image begins 25 pixels from the top edge.

Using Relative Units

.rem-offset {
  background-position-y: 2rem;
}
.em-offset {
  background-position-y: 1.5em;
}

Relative units allow positioning offsets to scale with font sizes. The rem unit is based on the root element's font size, while em is based on the element's font size.

Using Negative Lengths

.negative-offset {
  background-position-y: -20px;
}

A negative length shifts the image above the top edge of its normal starting position.

This can be useful for cropping decorative graphics or shifting a larger background image so a particular vertical portion remains visible.

Using calc()

.calculated-offset {
  background-position-y: calc(50% + 20px);
}

The image is centered vertically and then shifted 20 pixels downward.

Use calculated positions when a design requires a combination of proportional alignment and a fixed offset.

Percentage Values

Percentage values align a point within the background image with the corresponding percentage point of the positioning area.

.percentage-position {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position-y: 50%;
}

The 50% value aligns the image's vertical center with the center of the positioning area.

How Percentage Positioning Is Calculated

The browser subtracts the rendered image height from the positioning area's height and applies the specified percentage to the difference.

For example, consider a positioning area that is 300 pixels tall and an image that is 100 pixels tall.

Percentage Calculated Offset Result
0% 0px Image aligned top
25% 50px Image shifted 50px downward
50% 100px Image centered
75% 150px Image shifted 150px downward
100% 200px Image aligned bottom

Percentage Positioning Formula

/* Vertical offset:
   (positioning area height - image height) * percentage */
.example {
  background-position-y: 75%;
}

If the background image and positioning area have the same height, changing the percentage does not move the image vertically.

If the image is taller than the positioning area, the difference becomes negative. Percentage positioning can then control which portion of the oversized image remains visible.

Percentages are especially useful when an element changes height across different screen sizes.

Top and Bottom Edge Offsets

The background-position-y property can position an image at a specific distance from either vertical edge.

Offset from the Top Edge

.top-offset {
  background-position-y: top 20px;
}

The image begins 20 pixels below the top edge of the positioning area.

Offset from the Bottom Edge

.bottom-offset {
  background-position-y: bottom 20px;
}

The image's bottom edge is positioned 20 pixels above the bottom edge of the positioning area.

Percentage Edge Offsets

.bottom-percentage-offset {
  background-position-y: bottom 10%;
}

The image is positioned using an offset equal to 10% of the difference between the positioning area's height and the rendered image height, measured inward from bottom alignment.

Responsive Bottom Alignment

.decorative-card {
  background-image: url("decoration.svg");
  background-size: 48px 48px;
  background-repeat: no-repeat;
  background-position-y: bottom 15px;
}

The image stays 15 pixels above the bottom edge as the card changes height.

This is often easier to maintain than calculating a top offset for elements with flexible dimensions.

Working with background-position-x

The background-position-x and background-position-y properties control the horizontal and vertical components of background positioning independently.

.separate-axes {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position-x: right;
  background-position-y: bottom;
}

This is equivalent to using the background-position shorthand with right bottom.

.combined-axes {
  background-position: right bottom;
}

Changing Only One Axis

.decorative-panel {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-position-y: bottom 20px;
}

The final declaration changes the vertical position while leaving the horizontal position centered.

Independent Numeric Values

.independent-offsets {
  background-position-x: 25%;
  background-position-y: 40px;
}

The image is positioned at 25% horizontally and 40 pixels from the top vertically.

Use the separate longhand properties when only one axis needs to change without replacing the other axis's settings.

Working with background-size

The background-size property controls the rendered dimensions of the background image, which affects vertical positioning calculations.

Using a Fixed Image Size

.fixed-size-background {
  background-image: url("icon.png");
  background-size: 80px 80px;
  background-repeat: no-repeat;
  background-position-y: center;
}

The image is rendered at 80 by 80 pixels and centered vertically.

Positioning an Image with cover

.hero {
  min-height: 300px;
  background-image: url("hero.jpg");
  background-size: cover;
  background-repeat: no-repeat;
  background-position-y: center;
}

The cover value scales the image until it covers the positioning area. Vertical centering can crop equal portions from the top and bottom when the image is taller than the area.

Choosing Which Part Remains Visible

.hero-top {
  background-size: cover;
  background-position-y: top;
}
.hero-bottom {
  background-size: cover;
  background-position-y: bottom;
}

These values can reveal different vertical portions of an oversized background image.

If the rendered image height matches the positioning area's height, changing its vertical percentage position may produce no visible movement.

Working with background-origin

The background-origin property determines which area of the CSS box model is used to position background images.

Origin Vertical Positioning Area
border-box Includes the element's border, padding, and content heights.
padding-box Includes the padding and content heights. This is the default.
content-box Uses only the content height.

Positioning Relative to the Content Box

.content-aligned {
  padding: 30px;
  border: 5px solid #1769aa;
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-origin: content-box;
  background-position-y: bottom;
}

The image aligns with the bottom edge of the content box rather than the padding or border edge.

Positioning Relative to the Border Box

.border-aligned {
  padding: 30px;
  border: 5px solid #1769aa;
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-origin: border-box;
  background-position-y: bottom;
}

The image aligns with the outer bottom edge of the border box.

For background layers using background-attachment: fixed, the positioning area is generally the viewport, so changing background-origin has no effect on those layers.

Multiple Background Layers

The background-position-y property accepts comma-separated values for positioning multiple background images independently.

.layered-panel {
  background-image: url("icon-one.png"), url("icon-two.png");
  background-position-x: left, right;
  background-position-y: top, bottom;
  background-repeat: no-repeat, no-repeat;
}

The first image appears at the top-left corner. The second appears at the bottom-right corner.

Using Different Vertical Offsets

.multiple-offsets {
  background-image: url("one.png"), url("two.png"), url("three.png");
  background-position-x: center;
  background-position-y: 15px, center, bottom 20px;
  background-repeat: no-repeat;
}

The first image is positioned 15 pixels from the top, the second is centered vertically, and the third is positioned 20 pixels from the bottom.

The single horizontal value is repeated for all three layers, keeping them horizontally centered.

Matching Values to Layers

Each vertical position corresponds to the background image at the same position in the comma-separated list.

If fewer positions are provided than image layers, the browser repeats the list as necessary. Extra positions are not used when there are fewer image layers.

The first background image is painted above subsequent images, regardless of their vertical positions.

Shorthand Properties and Resets

The background-position-y property is the vertical component of the background-position shorthand.

.panel {
  background-position-x: right;
  background-position-y: bottom;
}

This is equivalent to the following shorthand declaration:

.panel {
  background-position: right bottom;
}

Changing the Vertical Position After the Shorthand

.panel {
  background-position: right center;
  background-position-y: bottom;
}

The final declaration changes the vertical position to the bottom while preserving the right horizontal alignment.

Shorthand Override Behavior

.panel {
  background-position-y: bottom;
  background-position: center top;
}

The later background-position declaration sets both axes, replacing the earlier vertical position with top.

Using the background Shorthand

.panel {
  background-position-y: bottom;
  background: url("pattern.png") no-repeat;
}

The background shorthand resets background positioning to its initial values when no position is specified.

To preserve a vertical position, specify it after the shorthand.

.panel {
  background: url("pattern.png") no-repeat;
  background-position-y: bottom;
}

The final declaration places the image at the bottom while leaving its horizontal position at the initial value of 0%.

background-position-y Example

The following example compares four vertical background positions: top, center, bottom, and bottom 15px.

Each box contains the same circular gradient image. The horizontal position remains centered so only the vertical placement changes.

<div class="background-position-y-demo">
  <div class="position-box top">top</div>
  <div class="position-box center">center</div>
  <div class="position-box bottom">bottom</div>
  <div class="position-box offset">bottom 15px</div>
</div>
.background-position-y-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
}
.position-box {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 170px;
  padding: 15px;
  box-sizing: border-box;
  border: 2px solid #1769aa;
  border-radius: 6px;
  background-color: #e8f2fb;
  background-image: radial-gradient(circle, #1769aa 0 60%, #69b7e8 62% 75%, transparent 77%);
  background-size: 54px 54px;
  background-repeat: no-repeat;
  background-position-x: center;
  color: #173b5e;
  font-weight: bold;
  text-align: center;
}
.position-box.top {
  background-position-y: top;
}
.position-box.center {
  background-position-y: center;
}
.position-box.bottom {
  background-position-y: bottom;
}
.position-box.offset {
  background-position-y: bottom 15px;
}

The vertical position is the only background setting that changes between the four boxes.

Browser Result
top
center
bottom
bottom 15px

The first box aligns the circular image with the top edge. The second centers it vertically.

The third aligns the image with the bottom edge, while the fourth places it 15 pixels above that edge.

All four images remain horizontally centered because their background-position-x values are identical.

Important Considerations

Keep the following points in mind when using background-position-y:

  • Default value: The initial value is 0%, equivalent to top.
  • Vertical positioning: The property changes only the vertical position of background images.
  • Horizontal positioning: Use background-position-x to control horizontal placement independently.
  • Keywords: The top, center, and bottom keywords provide common vertical alignments.
  • Length values: Numeric lengths provide fixed or relative vertical offsets.
  • Percentage values: Percentages align corresponding points of the image and positioning area.
  • Edge offsets: Use values such as bottom 20px to maintain a specified distance from the bottom edge.
  • Negative values: Negative lengths can shift images above the top edge of the positioning area.
  • Background size: The image's rendered height affects percentage positioning and the visible result of cropping.
  • Background origin: The positioning area is controlled by background-origin and defaults to the padding box.
  • Multiple layers: Comma-separated values can assign different vertical positions to individual background images.
  • Background repetition: Repeating patterns can make vertical positioning changes less noticeable.
  • Shorthand declarations: Later background-position or background declarations can reset the vertical position.
  • Element layout: Changing the background position does not move the element or its foreground content.

Use background-position-y when only the vertical placement of a background image needs to change while preserving its horizontal position.

Browser Support

The background-position-y property is supported in modern versions of Chrome, Edge, Firefox, Safari, and other major browsers.

Basic vertical keywords, lengths, and percentages have broad support. More advanced edge-offset syntax may have different compatibility requirements in older browsers.

Providing a Fallback

.decorative-panel {
  background-image: url("icon.png");
  background-repeat: no-repeat;
  background-position: center bottom;
  background-position-y: bottom 20px;
}

The background-position declaration provides a widely supported fallback. Browsers that recognize the later vertical edge offset can position the image 20 pixels above the bottom edge.

Visit Can I Use? to check browser compatibility for the property.

Specifications

The background-position-y property is defined in the CSS Backgrounds and Borders Module Level 4 specification. The related background-position shorthand is also described in Level 3.

CSS Backgrounds and Borders Module Level 4

CSS Backgrounds and Borders Module Level 3