Sets or retrieves the type of positioning used for the object.
position: static | relative | absolute | fixed | page
Default. Object has no special positioning; it follows the layout rules of HTML.
Starting in Internet Explorer 7. Object is positioned relative to the viewport containing the content.
Internet Explorer 10. Positioned floats only. (The display property must be set to -ms-positioned.) Object is positioned relative to the nearest initial containing block. This may be the browser or application window or a content container such as an iframe. The bottom, top, left, and right properties are used to position the element relative to the boundaries of the viewport that the positioned float would normally be placed in (that is, if position:static was set). For more information, see Positioned Floats.
|Applies To||All elements|
- CSS 2.1, Section 9.3.1
Setting the property to absolute pulls the object out of the "flow" of the document and positions it regardless of the layout of surrounding objects. If other objects already occupy the given position, they do not affect the positioned object, nor does the positioned object affect them. Instead, all objects are drawn at the same place, causing the objects to overlap. This overlap is controlled by using the z-index attribute or property. Absolutely positioned objects do not have margins, but they do have borders and padding.
To enable absolute positioning on an object you must specify at least one of the top, bottom, left, or right properties, in addition to setting the position property to absolute. Otherwise, these positioning properties use their default value of absolute, which causes the object to render immediately after the preceding elements, according to the layout rules of HTML
Input from pointing devices, such as the mouse, does not penetrate through overlapping elements even if the elements are not visible. This is also true for positioned elements with a negative z-index unless:
- The parent is a scrolling container (that is, its overflow property is set to auto or scroll).
- The parent is positioned (that is, its position property is set to absolute or relative).
Setting the property to relative places the object in the natural HTML flow of the document, but offsets the position of the object based on the preceding content. The following syntax shows how to create superscript text by placing the text in a span that is positioned relative to the remaining text in the paragraph.
<p>The superscript in this name <span style="position: relative; top: -3px">xyz</span> is "xyz".</p>
Text and objects that follow a relatively positioned object occupy their own space and do not overlap the natural space for the positioned object. In contrast, text and objects that follow an absolutely positioned object occupy what would have been the natural space for the positioned object before it was pulled out of the flow. Placing an absolutely positioned object beyond the viewable area of the window causes a scroll bar to appear. When relatively positioned objects are placed beyond the viewable area, a scroll bar is not shown.
The size of the content determines the size of objects with layout. For example, setting the height and position properties on a div object gives it layout. The content of the div determines the size. In this case, the content determines the size of the width.
Starting in Internet Explorer 7. Fixed positioning is only supported for pages using a strict <!DOCTYPE> directive.
For an overview about how to use dynamic positioning, see About Element Positioning.
Internet Explorer 10. Setting the position property to page requires that the display property be set to -ms-positioned. Furthermore, setting display to -ms-positioned makes the other values for the position property behave in the following ways:
- static Default. The positioned float is laid out according to normal HTML flow.
- absolute The positioned float is laid out relative to its containing block, but the positioned float will affect the normal flow of its container. Inline content wraps around the positioned float; the positioned float is not laid out on top of inline content.
- relative The positioned float is laid out relative to where it would fall in the normal flow. The bottom, top, left, and right properties can be used to calculate an offset from the element's position in the normal flow. Content will flow around the original position of the element, and the actual positioned float will be superimposed on top of inline content.
- fixed The positioned float is laid out relative to the initial position of the viewport, or browser window. (The positioned float's position is not updated as the viewport moves due to scrolling.)
For more information, see Positioned Floats.
This examples uses the position property's absolute, static, and relative values to change the position of the text.
Build date: 11/29/2012