A scroll-driven floating header that morphs width, radius, and elevation as the user scrolls.
Made by raouf.codesOverview
Core Concept
The FloatingHeader component transforms a static navigation bar into a scroll-reactive, motion-enhanced header. Built on top of Framer Motion's useScroll and useSpring, it interpolates width, border-radius, background, and shadow as the user scrolls — giving a polished "shrink-on-scroll" effect with zero JavaScript layout thrashing.
Visual transitions use direct motion values for geometry and theme CSS variables (--primary, --accent, --secondary, --background, --foreground) for color, so the component stays aligned with your design tokens.
Key Features
- Scroll-driven morph — Width, radius, shadow, and background animate smoothly via spring physics
- Theme-aware visuals — Background and shadow colors derive from theme tokens, so the header automatically adapts to your palette
- Variant system — Full support for
intent,styling,size,shape,elevation, andtargetWidth - Glass styling — Built-in
backdrop-blurglass morphism variant - Semantic markup — Renders as a
<header role="banner">
Installation
Usage
Basic
Composition
Combine with a glass look, pill shape, and floating elevation:
API Reference
FloatingHeader
| Prop | Type | Default |
|---|---|---|
intent? | enum | "neutral" |
styling? | enum | "glass" |
size? | enum | "md" |
shape? | enum | "rounded" |
elevation? | enum | "raised" |
targetWidth? | number | 85 |
scrollRef? | RefObject<HTMLElement | null> | - |
...props? | HTMLMotionProps<"header"> | - |
Accessibility
- Landmark — Renders as
<header role="banner">for assistive technology detection - Focus management — Place focusable navigation items inside; the header itself is not interactive
- Reduced motion — Spring animations respect
prefers-reduced-motionwhen configured via Framer Motion's global settings
| Key | Action |
|---|---|
Tab | Moves focus through child navigation items |
Built by raouf.codes. The source code is available on GitHub.
Last updated: 4/4/2026