Skip to content
Back to Concepts
CSS UniverseTrack 2: GeometryPositioning
1st Year CS Foundation · Core Track 2Core Concept 08

CSS Positioning

Escape the normal document flow. Master static, relative, absolute, fixed, sticky, and the 3D stacking context of z-index.

1. The 5 Positioning Modes

Where Do Elements Anchor?

static

The Default. Natural document flow. top, left, and z-index are completely ignored!

relative

The Ghost Footprint. Shifts from where it would have been, but leaves its space reserved. Also acts as anchor for absolute children!

absolute

Ripped from Flow. Takes zero space. Teleports relative to its closest non-static ancestor (usually a position: relative parent).

fixed

Glued to Viewport. Anchored to the browser screen glass. Never moves, even when user scrolls (e.g. sticky headers, back-to-top buttons).

sticky

The Hybrid. Behaves like relative until scroll threshold (e.g. top: 0) is reached, then sticks like fixed!

2. Live Positioning Studio

Inspect Relative vs Absolute Movement

Position Mode:
Container (position: relative, overflow: hidden)
Sibling Element A (occupies flow space)
position: relative
top: 20px, left: 40px
Sibling Element B (notice how it moves when Target is absolute!)
3. The Most Common Real-World Pattern

The Parent `relative` + Child `absolute` Pattern

How do you place a badge on the top-right corner of a card? Or a close icon on a modal dialog?

/* 1. Set parent container to position: relative */
.card {
position: relative; /* Becomes anchor point! */
}
/* 2. Pin child to the top-right corner */
.card__badge {
position: absolute;
top: 12px;
right: 12px;
}
4. Hands-on Positioning Workbench

Full Positioning Visualizer

CSS Positioning & Flow

Positioning & Transforms Studio

Master the vital difference between CSS Positioning (normal flow offsets) and CSS Transforms (GPU-accelerated translate, scale, and rotate).

Try these

  • Switch between static and relative: Notice offsets (top/left) only take effect when not static.
  • Choose absolute and toggle "Parent has position: relative": Watch the box escape to the outer viewport when parent is static!
  • Select sticky and scroll inside the preview stage to see it stick once reaching top: 24px.
  • Adjust z-index to see the card dive underneath or rise above sibling elements.
Relative elements keep their footprint in the document layout, but shift visually relative to where they would naturally be.
Mode: relative · top: 24px, left: 32px, z-index: 2Interactive Canvas
Containing Block: position: relative
Sibling Block 1 (Normal Flow)static · z-index: 1
👻 Ghost: Space reserved in normal document flowOccupied
Target Box (relative)z: 2

Shifted (24px, 32px) from original slot.

Sibling Block 2 (Normal Flow)static · z-index: 1
Scroll content filler 3 (Scroll me to see sticky anchor!)
Scroll content filler 4 (Scroll me to see sticky anchor!)
Scroll content filler 5 (Scroll me to see sticky anchor!)
Scroll content filler 6 (Scroll me to see sticky anchor!)
/* Container Context */ .stage-container { position: relative; /* Containing block */ } /* Positioned Element */ .target-card { position: relative; top: 24px; left: 32px; z-index: 2; /* Remains in normal flow: offset is purely visual! */ }
Next in Track 2

9. Floats & Clearfix

Text wrapping around images, clearfix micro-hacks, and Block Formatting Contexts.

Continue to Floats