Sticky header
The header stays at the top while scrolling. Anchor links need scroll-margin so headings do not hide under it.
CSS · Sticky headerBeginner
header {
position: sticky;
top: 0;
z-index: 50;
background: #fff;
box-shadow: 0 1px 0 rgba(0, 0, 0, .08);
}
/* Anchors land below the header */
[id] { scroll-margin-top: 80px; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }stickyheaderlayout