CSS <position> Data Type
The <position> data type is a point in a box, written with keywords such as left, center or top, lengths and percentages, as used by background-position.
Description
The <position> CSS data type represents a point in a two-dimensional space, used to place an image or shape inside an element's box. It is written as one to four values made from the keywords left, center, right, top and bottom, and from <length> and <percentage> offsets. It is not the same as the position property, which chooses how an element is laid out (static, relative, absolute and so on).
The <position> type is used by properties such as background-position, object-position, mask-position, offset-position, perspective-origin and transform-origin, and after the keyword at in functions such as radial-gradient(), conic-gradient(), circle() and ellipse().
With a single value, the other axis defaults to center, so left means left center and 20% means 20% center. With two values, the first is normally horizontal and the second vertical, although two keywords can be given in either order (top left and left top are the same). With three or four values, each keyword is followed by an offset measured from that edge, so right 20px bottom 10px places the point 20px from the right and 10px from the bottom. Percentages are special: 25% 75% lines up the point 25% across the image with the point 25% across the container, which is why 0% aligns the left edges and 100% aligns the right edges.
Examples:
/* Keywords */
.hero { background-position: center top; }
/* Lengths and percentages */
.avatar { object-position: 50% 20%; }
/* Edge offsets: 20px from the right, 10px from the bottom */
.badge-bg { background-position: right 20px bottom 10px; }
/* In functions after "at" */
.spotlight {
background: radial-gradient(circle at 30% 40%, #fff, #0f172a);
}
Interactive Demo
Syntax
<position> = [ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]
Values
- leftIs equivalent to a horizontal position of 0%.
- rightIs equivalent to a horizontal position of 100%.
- topIs equivalent to a vertical position of 0%.
- bottomIs equivalent to a vertical position of 100%.
- centerIs equivalent to position of 50% in the applicable direction.
- <length-percentage>An offset from the left (horizontal) or top (vertical) edge, or, when it follows a keyword, from that edge. Percentages align the same point of the item and the container.
Example
Browser Support
The following information will show you the current browser support for the CSS position data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
Desktop





Tablets & Mobile





