CSS position Property

Beginner
7 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The position property sets how an element is placed in the document. Pair it with inset offsets such as top, left, or inset.

static is normal flow. relative offsets from that spot but keeps the original space. absolute and fixed leave the flow. sticky sticks after a scroll threshold. Anything except static is a positioned element.

Standard-track.

Not deprecated. Baseline widely available. Sticky needs a non-auto inset and a scrolling ancestor to stick.

CSS Syntax

syntax.css
position: static | relative | absolute | fixed | sticky | initial | inherit;

Offsets apply after you leave static. Without an inset, sticky behaves like relative on that axis.

Property Values

ValueDescriptionTry it
staticDefault. Normal flow; offsets ignoredTry it
relativeOffset from normal spot; space keptTry it
absoluteOut of flow; nearest positioned ancestorTry it
fixedOut of flow; relative to the viewportTry it
stickyRelative until threshold, then sticksTry it
initial / inheritReset to static, or take the parent valueTry it

How to Use position

Pick the mode first, then add the inset that matches that mode.

  1. Leave static when normal document flow is enough.
  2. Use relative for a small nudge, or to create a containing block for absolute children.
  3. Use absolute / fixed for overlays and pinned UI, with top / left (or inset).
  4. Use sticky with a threshold such as top: 0 inside a scrolling container.
PieceRequired?Role
position keywordYesChooses the positioning scheme
Inset (top / left / …)UsuallyWhere the box moves or sticks
Positioned ancestorFor absoluteNearest non-static ancestor is the containing block
Scrolling ancestorFor stickyoverflow other than visible often provides the scrollport

Live Preview

Same box and top: 24px; left: 24px. Change only position. Scroll the panel for sticky.

The parent is position: relative. Scroll inside the panel when testing sticky.

Stage

Line one in normal flow.

Box

Line two in normal flow.

More content to scroll.

Keep scrolling for sticky.

End of the panel.

position: relative — Offset from its normal spot; original space kept.

CSS Examples

Each snippet focuses on position. Use Try It Yourself for a live editor.

Example 1 — Relative Offset

Nudge a box from its normal place without removing it from flow.

CSS
<style>
  .box {
    position: relative;
    top: 16px;
    left: 24px;
  }
</style>

<p>Above</p>
<div class="box">Box</div>
<p>Below</p>
Try It Yourself

How It Works

  1. Stay in flow. The box still owns its original layout slot between Above and Below.
  2. Apply an offset. top and left move the painted box from that slot.
  3. Neighbors do not follow. Below does not slide up into the gap the paint left behind.
  4. Bonus. A relative box also becomes a containing block for absolute children.

Example 2 — Absolute in a Relative Parent

Pin a child to a corner of a positioned parent.

CSS
<style>
  .parent {
    position: relative;
  }

  .badge {
    position: absolute;
    top: 8px;
    right: 8px;
  }
</style>

<div class="parent">
  Card content
  <span class="badge">New</span>
</div>
Try It Yourself

How It Works

  1. Create a containing block. position: relative on the parent (without needing offsets) makes it positioned.
  2. Leave the flow. absolute on the badge removes it from normal layout.
  3. Offset from the parent. top and right measure from the parent’s edges, not the viewport.
  4. Without a positioned ancestor. Absolute would climb to a higher ancestor or the initial containing block instead.

Example 3 — Sticky Header

Stay in flow, then stick at top: 0 while the panel scrolls.

CSS
<style>
  .panel {
    height: 140px;
    overflow: auto;
  }

  .stick {
    position: sticky;
    top: 0;
  }
</style>

<div class="panel">
  <div class="stick">Sticky</div>
  <p>Scroll me.</p>
  <p>More text.</p>
  <p>Keep going.</p>
</div>
Try It Yourself

How It Works

  1. Make a scrollport. overflow: auto and a fixed height let the panel scroll.
  2. Set sticky + threshold. position: sticky with top: 0 sticks when the box reaches the top edge.
  3. Still in flow at first. Until the threshold, the box behaves like relative.
  4. Stuck only inside the ancestor. Sticky stops at the edges of its containing block; it does not float forever like fixed.

Edge Cases & Pitfalls

If offsets or sticky fail, one of these is usually why.

static

Offsets ignore static

top, left, and friends do nothing on a static box. Change the position keyword first.

absolute

Absolute climbs to a positioned ancestor

If every parent is static, absolute uses a higher containing block. Set relative (or another non-static value) on the intended parent.

sticky

Sticky needs an inset and a scrollport

Without top/left/…, sticky acts like relative. Also check that an ancestor can scroll and is not clipped in a way that prevents sticking.

fixed

transform can trap fixed

A filtered, transformed, or perspective ancestor can become the containing block for fixed, so the box sticks to that ancestor instead of the viewport.

stack

Layering uses z-index

Positioned elements can form stacking contexts. Control overlap with z-index when boxes cover each other.

Browser Support

position is a browser layout property. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

position

static / relative / absolute / fixed: all modern browsers and Internet Explorer. sticky: Chrome 56+, Firefox 59+, Safari 13+, Edge 16+.

97% Modern browser support
Google Chrome 1+ · sticky 56+
Full support
Mozilla Firefox 1+ · sticky 59+
Full support
Apple Safari 1+ · sticky 13+
Full support
Microsoft Edge 12+ · sticky 16+
Full support
Opera 4+ · sticky 43+
Full support
Samsung Internet 1+ · sticky 6+
Full support
Internet Explorer All but sticky
Partial
position Widely supported

Bottom line: Safe for everyday layout. Prefer sticky only when you can accept no support in Internet Explorer, or provide a non-sticky fallback.

Key Takeaways

  • Role: choose how a box participates in layout and where offsets apply.
  • Common values: static, relative, absolute, fixed, sticky.
  • Initial value: static. Not inherited.
  • Pairing: use inset offsets; use a positioned parent for absolute children.

One line: position picks the scheme; top/left/inset pick the place.

Frequently Asked Questions

It sets how an element is placed in the document. static follows normal flow. relative offsets from its normal spot. absolute and fixed leave the flow. sticky sticks after a scroll threshold.
The initial value is static. top, right, bottom, left, and z-index do not move a static element.
relative keeps the element in flow and shifts it from its original place. absolute removes it from flow and places it against the nearest positioned ancestor (or the initial containing block).
Absolute uses the closest ancestor with position other than static as its containing block. A common pattern is position: relative on the parent so the child stays inside that box.
Sticky needs a non-auto inset such as top: 0, and a scrolling ancestor. If both insets on an axis are auto, sticky behaves like relative on that axis.
static, relative, absolute, and fixed are supported in all modern browsers and IE. sticky is Baseline and widely available (Chrome 56+, Firefox 59+, Safari 13+, Edge 16+). It is a browser layout property, not a Node.js feature.

Next: quotes

Learn how to set custom quotation marks for the quotes property.

quotes tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful