Utilizor
Contact Us

CSS Position

The position property specifies the type of positioning method used for an element (static, relative, fixed, absolute or sticky).

CSS Position Property

The position property specifies the type of positioning method used for an element.

There are five different position values:

  • static
  • relative
  • fixed
  • absolute
  • sticky

Example 1: position: static;

HTML elements are positioned static by default. Static positioned elements are not affected by the top, bottom, left, and right properties.

This div element has position: static;

Example 2: position: relative;

An element with position: relative; is positioned relative to its normal position.

This div element has position: relative;

Example 3: position: absolute;

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed).

This div element has position: relative;
This div element has position: absolute;

Example 4: position: fixed;

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled.

This div element has position: fixed;

Example 5: position: sticky;

An element with position: sticky; is positioned based on the user's scroll position.

I am sticky!

Scroll down to see the sticky effect.

Scroll...

Scroll...

Example

div.relative {
  position: relative;
  left: 30px;
  border: 3px solid #73AD21;
}

div.absolute {
  position: absolute;
  top: 80px;
  right: 0;
  width: 200px;
  height: 100px;
  border: 3px solid #73AD21;
}