Skip to content
BENIBIX Learn

CSS Position

Development🌐 Web DevelopmentBrowser Code

Also known as position Property, position: absolute, position: sticky, position: fixed

The CSS rule that sets where a box goes. It can stay in line, move, or stick in view.

Think of it like

It is like choosing where a sticker goes. In a row, on a corner, or stuck to the window.

Example

Lucy wants a Chat button that stays in the corner while people scroll. She gives it position: fixed with bottom and right of 16px.

Why it matters

Pop-ups, sticky menus and badges on pictures all use it. Most layout, though, is better done with flexbox or grid.

Definition

The CSS position property sets how an element is placed on the page. static is the default, and the box sits in the normal flow. relative nudges the box from where it would be. absolute takes the box out of the flow and pins it inside its nearest placed parent. fixed pins it to the window, so it stays put as you scroll. sticky scrolls along, then sticks at an edge.

Example code

css
.chat { position: fixed; bottom: 16px; right: 16px; }
.menu { position: sticky; top: 0; }
The chat button stays in the corner. The menu scrolls up, then sticks to the top.
The five position values, side by side, each with the same box.

Common mistake

Using absolute when the parent has no position set. The box then jumps to a far corner of the page.

Key takeaways

  1. 1
    static by default. The box stays in the normal flow.
  2. 2
    Pinned to a parent. absolute needs a placed parent.
  3. 3
    Pinned to the window. fixed and sticky stay in view.

Learn it properly