CSS position property
Example
Locate
element:
h2
{
position:
absolute
;
left:
100
px
;
top:
150
px
;
}
Try it »
There are more examples at the bottom of this page.
Property definition and usage
The position property specifies the type of positioning method used for an element (static, relative, absolute, or fixed).
| Default value: | static |
|---|---|
| Inherited: | no |
| Version: | CSS2 |
| JavaScript syntax: | object.style.position="absolute" |
Browser support
The numbers in the table indicate the first browser version that supports this property.
| property | |||||
|---|---|---|---|---|---|
| position | 1.0 | 7.0 | 1.0 | 1.0 | 4.0 |
Attribute values
| Value | Description |
|---|---|
| absolute |
Generates an absolutely positioned element, positioned relative to the first parent element whose position is other than static. The element's position is specified through the "left", "top", "right", and "bottom" properties. |
| fixed |
Generates a fixed-positioned element, positioned relative to the browser window. The element's position is specified through the "left", "top", "right", and "bottom" properties. |
| relative |
Generates a relatively positioned element, positioned relative to its normal position. Therefore, "left:20" adds 20 pixels to the element's LEFT position. |
| static | Default value. No positioning; the element appears in the normal flow (ignoring top, bottom, left, right, or z-index declarations). |
| sticky |
Sticky positioning, which is based on the user's scroll position. It behaves like position:relative; but when the page scrolls beyond the target area, it behaves like position:fixed; and stays fixed at the target position. Note: Internet Explorer, Edge 15, and earlier IE versions do not support sticky positioning. Safari requires the -webkit- prefix (see the examples below). |
| inherit | Specifies that the value of the position property should be inherited from the parent element. |
| initial | Set this property to its default value; for details see CSS initial keyword. |
More examples
Position:relative
This example demonstrates how an element is positioned relative to its normal position.
Related Articles
CSS Tutorial: CSS Position