Performance: Position fixed and sticky
This concept affects page rendering speed and visual stability by controlling element positioning and triggering layout recalculations.
Jump into concepts and practice - no test required
header { position: sticky; top: 0; }header { position: fixed; top: 0; width: 100%; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| position: fixed | Element removed from flow, no DOM ops for siblings | 1 reflow on load, possible reflows on resize | Medium paint cost due to compositing | [!] OK |
| position: sticky | Element remains in flow until sticky activates | Reflows triggered on scroll when sticky activates | Lower paint cost, mostly compositing | [OK] Good |
position: fixed; do to an element on a webpage?position: fixed; stay in the same place on the screen regardless of scrolling.position: sticky; with an offset like top: 10px;.<style>
header {
position: sticky;
top: 0;
background: lightblue;
padding: 1rem;
}
</style>
<header>Sticky Header</header>
<div style='height: 2000px;'>Content</div>position: sticky; and it doesn't stick. What is a likely cause?overflow: hidden; or auto can prevent sticky from working.