Performance: Sticky header and footer
Sticky headers and footers affect page rendering and scrolling performance by keeping elements fixed during scroll.
<header class="sticky top-0 bg-gray-800 h-16"></header> <footer class="sticky bottom-0 bg-gray-800 h-16"></footer>
<header class="fixed top-0 left-0 w-full h-16 bg-gray-800"></header> <footer class="fixed bottom-0 left-0 w-full h-16 bg-gray-800"></footer>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed header/footer | Low (2 nodes) | Multiple on scroll | High due to repaint on scroll | [X] Bad |
| Sticky header/footer | Low (2 nodes) | Single on layout | Low repaint cost on scroll | [OK] Good |
sticky do when applied to a header or footer?sticky class makes an element stick to a position relative to the viewport when scrolling.sticky with bottom-0 so it sticks to the bottom edge.top-0 sticks to top, fixed is different positioning, and absolute does not stick on scroll.sticky top-0 bg-white shadow classes to a header element in Tailwind CSS?sticky top-0 makes the header stick to the top of the viewport. bg-white sets a white background. shadow adds a subtle shadow.z-50 increases the z-index, bringing the header above other elements.sticky top-0 for header and sticky bottom-0 for footer, which is correct for sticky header and footer.overflow-auto and height calculated as full viewport minus header/footer height, allowing scrolling between sticky elements.Pass the test and this pattern moves unknown