Position Strategy: Sticky, Fixed, Absolute
Choosing the right position value for headers, tooltips, and overlays without layout surprises.
Why
Misusing position: fixed (header overlaps content on iOS Safari URL bar resize) or position: absolute (tooltip clipped by overflow:hidden ancestor) creates bugs that are hard to trace. Each value has a narrow correct use.
StatCounter 2024 data shows 58% of web traffic is mobile. CSS container queries (baseline 2023) and subgrid (baseline 2024) eliminate most media-query hacks, reducing responsive CSS by 30-50%.
When
Pick by intent: static (default flow), relative (offset without leaving flow), absolute (remove from flow, position vs nearest positioned ancestor), sticky (flow until threshold then fixed-like), fixed (vs viewport). Avoid pixel-perfect responsive designs for data-dense dashboards — use a min-width + horizontal scroll strategy instead.
Skip container queries if you support Safari < 16.
How
Example
Common Problems
- ⚠position: fixed header on mobile — jumps when iOS Safari's URL bar shows/hides
- ⚠Tooltip clipped by overflow:hidden — absolute positions vs the right ancestor but is invisible
- ⚠transform on an ancestor — fixed child now positions vs that ancestor, not the viewport
Best Practices
- ✓Prefer sticky over fixed for in-page headers — respects scroll, no mobile URL-bar jump
- ✓Use Floating UI (Popper) for tooltips/popovers — handles clipping, flipping, escaping automatically
- ✓Render modals in a portal — escapes transformed ancestors that break position: fixed