CSS position
Property
Example
Position an <h2>
element:
h2 {
position: absolute;
left: 100px;
top: 150px;
}
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 specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
position | 1.0 | 7.0 | 1.0 | 1.0 | 4.0 |
Property Values
Value | Description |
---|---|
absolute | Generates an absolutely positioned element, relative to the first parent element that is not statically positioned. The element's position is specified by "left", "top", "right", and "bottom" properties. |
fixed | Generates a fixed positioned element, relative to the browser window. The element's position is specified by "left", "top", "right", and "bottom" properties. |
relative | Generates a relatively positioned element, relative to its normal position. Thus, "left:20" adds 20 pixels to the element's LEFT position. |
static | Default value. No positioning, the element appears in the normal flow (ignores top, bottom, left, right, or z-index declarations). |
sticky | Sticky positioning, based on the user's scroll position. It behaves like position:relative within its parent until a given offset threshold is met in the viewport, then it behaves like position:fixed . Note: Internet Explorer, Edge 15 and earlier versions do not support sticky positioning. Safari requires the -webkit- prefix (see the example below). |
inherit | Specifies that the position property should be inherited from the parent element. |
initial | Sets this property to its default value. See CSS initial keyword for more details. |
More Examples
Related Articles
CSS Tutorial: CSS Position