W3docs

CSS background-position-y Property

The background-position-y CSS property specifies the vertical position of a background-image. See examples and try them yourself.

The CSS background-position-y property sets the vertical position of a background image inside its element. It is the vertical half of the background-position shorthand: where background-position takes both a horizontal and a vertical value, background-position-y controls only the up/down placement, leaving the left/right placement to background-position-x.

You reach for it when you want to nudge a background image vertically without re-declaring the horizontal value — for example, pinning a watermark to the bottom of a hero section, or fine-tuning where a pattern starts. When an element has multiple background images, you can give one value per layer, separated by commas, and each value is matched to the corresponding image.

The vertical offset is measured against the background positioning area (by default the element's padding box). A length counts from the top edge downward; a percentage aligns matching points on the image and the area (see Values below).

Info

Negative values are valid — background-position-y: -20px shifts the image up, past the top edge.

Initial Valuetop
Applies toAll elements.
InheritedNo.
AnimatableNo.
VersionCSS3
DOM Syntaxobject.style.backgroundPositionY = "bottom";

Syntax

CSS background-position-y values

background-position-y: top | center | bottom | length | percentage | initial | inherit;

Example of the background-position-y property with the "top" value:

CSS background-position-y code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      html {
        min-height: 100vh;
      }
      body {
        padding-top: 30px;
        background: url("https://api.w3docs.com/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png") no-repeat;
        background-position-y: top;
      }
    </style>
  </head>
  <body>
    <h2>Background-position-y property example</h2>
  </body>
</html>

Result

CSS background-position-y top

Example of the background-position-y property with the "bottom" value:

CSS background-position-y bottom example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      html {
        min-height: 100vh;
      }
      body {
        background: url("https://api.w3docs.com/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png") no-repeat;
        background-position-y: bottom;
      }
    </style>
  </head>
  <body>
    <h2>Background-position-y property example</h2>
  </body>
</html>

Example of the background-position-y property with the "center" value:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      html {
        min-height: 100vh;
      }
      body {
        background: url("https://api.w3docs.com/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png") no-repeat;
        background-position-y: center;
      }
    </style>
  </head>
  <body>
    <h2>Background-position-y property example</h2>
  </body>
</html>

Example of the background-position-y property with the "length" value:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      html {
        min-height: 100vh;
      }
      body {
        padding-top: 30px;
        background: url("https://api.w3docs.com/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png") no-repeat;
        background-position-y: 90px;
      }
    </style>
  </head>
  <body>
    <h2>Background-position-y property example</h2>
  </body>
</html>

Example of the background-position-y property with the "percentage" value:

Percentages behave differently from lengths. With a length such as 90px, the top of the image is placed 90px below the top of the area. With a percentage, the point at N% down the image is aligned with the point N% down the area — so 0% is top, 100% is bottom, and 50% is center. This is what makes percentage values keep an oversized image visible no matter the container height.

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      html {
        min-height: 100vh;
      }
      body {
        padding-top: 30px;
        background: url("https://api.w3docs.com/uploads/media/default/0001/01/0710cad7a1017902166203def268a0df2a5fd545.png") no-repeat;
        background-position-y: 70%;
      }
    </style>
  </head>
  <body>
    <h2>Background-position-y property example</h2>
  </body>
</html>

Values

ValueDescription
topSpecifies the alignment of the top edge of the background image with the top edge of the background position layer.
centerSpecifies the alignment of the center of the background image with the center of the background position layer.
bottomSpecifies the alignment of the bottom edge of the background image with the bottom of the background position layer.
lengthSpecifies the vertical offset of the background image from the top edge of the background positioning layer.
percentageSpecifies the vertical offset of the background image relative to the container. 0% aligns the top edge of the background image with the top edge of the container, 100% aligns the bottom edge with the bottom edge of the container, and 50% vertically centers the background image.
initialSets the property to its default value.
inheritInherits the property from its parent element.

Practice

Practice
What is the function of the 'background-position-y' property in CSS?
What is the function of the 'background-position-y' property in CSS?
Was this page helpful?