CSS Position: static, relative, fixed, absolute

By Xah Lee. Date: . Last updated: .

CSS has a position property that can be used to:

The position property has 4 possible values:

div {position:static}

div {position:fixed}

div {position:relative}

div {position:absolute}
position ValueOwn LayerRelative To
staticno(Normal Flow) This is default.
relativenoRelative to its normal position
fixedyesRelative to window
absoluteyesRelative to its containing block. That is, the first parent that's not positioned static. If none found, then it's <html> tag.

To specify the offset, use the following:


div.x89647 {
top: 1px;
left: 1px;


The position:static is the default for all elements.

The position of element of position:static is either below the previous element, or to the right of the previous element.

If the previous element is a block element, then next element is positioned below it. (block elements are div, p, img, h1 etc.)

If the previous element is a inline element, then next element is positioned to the right of it (or below if container box width is reached). (inline elements are span, a (link), b (bold), etc.)


Use position:relative to adjust a element's position relative to its normal position.

BBB with relative position
<div id="box38155">
<div id="offset79397">BBB with relative position</div>
#box38155 {
 border:solid thin blue;

#offset79397 {
 border:solid thin red;

More detail, see

CSS: Relative Position


Use position:fixed to specify the positioning of a element with respect to the window.

When a element has position:fixed, that element goes into its own layer. The normal flow of elements will flow as if that element doesn't exist.


CSS: Fix Element to Window


position:absolute make the element go into its own layer.

position:absolute's offset is relative to its “containing block”.

A “containing block” is effectively the first parent element that has a position value other than “static”. When no parent has any of “position” spec, then it is relative to the <html> element.


Overlapping and z-index

When a element goes into a layer, it may overlap with other elements. To control which goes on top, you can use the attribute “z-index”. Like this:


[see CSS: z-index]

Layer Example

For practical examples of using layers, see:


Visual formatting model#propdef-position

Liket it? I spend 2 years writing this tutorial. Help me spread it. Tell your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Object Ref
  5. DOM Scripting
  6. SVG
  7. Blog