CSS background-position-y Property


Example

How to position a background-image on y-axis:

div {
  background-image: url('w3css.gif');
  background-repeat: no-repeat;
  background-position-y: center;
}
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The background-position-y property sets the position of a background image on the y-axis.

Tip: By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

Show demo ❯

Default value: 0%
Inherited: no
Animatable: yes. Read about animatable Try it
Version: CSS3
JavaScript syntax: object.style.backgroundPositionY="center" Try it

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
background-position-y 1.0 12.0 49.0 1.0 15.0
background-position-y
(with two value syntax)
Not supported Not supported 49.0 15.4 Not supported


CSS Syntax

background-position-y: value;

Property Values

Value Description Demo
top Positions background top on y-axis. Demo ❯
bottom Positions background bottom on y-axis. Demo ❯
center Positions background center on y-axis. Demo ❯
y% Top side is 0% on y-axis, and bottom side is 100%. Percentage value refers to height of background positioning area minus height of background image. Demo ❯
ypos Vertical distance from top side. Units can be pixels (0px) or any other CSS units. Demo ❯
ypos offset Two value syntax, only supported in Firefox and Safari.
- ypos is set either to "top" or "bottom".
- offset is vertical distance from background image and "top" or "bottom" side set with ypos. Units can be pixels or any other CSS units.
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

More Examples

Example

How to position a background-image to the top:

body {
  background-image: url('w3css.gif');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position-y: bottom;
}
Try it Yourself »

Example

How to position a background-image on y-axis using percent:

body {
  background-image: url('w3css.gif');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position-y: 50%;
}
Try it Yourself »

Example

How to position a background-image on y-axis using pixels:

body {
  background-image: url('w3css.gif');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-position-y: 80px;
}
Try it Yourself »

Related Pages

CSS tutorial: CSS Background

CSS reference: background-image property

CSS reference: background-position property

CSS reference: background-position-x property

HTML DOM reference: backgroundPosition property


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.