Position (CSS)

The CSS position property controls how an element is placed in the document and whether it responds to the top, right, bottom, and left offsets. Its values are static, relative, absolute, fixed, and sticky.

Web

static is the default (normal flow). relative offsets an element from its normal spot. absolute positions it relative to its nearest positioned ancestor. fixed pins it to the viewport, and sticky toggles between relative and fixed as you scroll.

Positioning is often used for overlays, tooltips, sticky headers, and badges placed on top of other elements.

Examples

CSS

.badge {
  position: absolute;
  top: 0;
  right: 0;
}

Output:

Pins the badge to the top-right corner of its nearest positioned ancestor.

Learn it in a lesson

See also

Back to the Dictionary