Back to elements
ElementLayoutFree

Sticky Header React component

A site header that stays out of the way: it slides up while you scroll down and comes back the moment you scroll up, turns compact and frosted after the first few pixels, shows reading progress along its edge, and folds its links into a menu on narrow screens.

When to use the Sticky Header component

Use Sticky Header for marketing sites, docs and blogs where navigation should always be one scroll-up away but shouldn't cover content while people read.

Use behavior="shrink" for apps and dashboards where the header holds controls people need at all times.

Installation

Add the Sticky Header component to your project with the shadcn CLI. It lands in components/sticky-header.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add https://reactframe.com/r/sticky-header.json

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Props

<StickyHeader /> accepts 9 props, all optional.

  • brand
    React.ReactNode
    Default: ( <span className="flex items-center gap-2 text-[15px] font-semibold tracking-[-0.01em]">…
  • links
    { label: string; href: string }[]
    Default: DEFAULT_LINKS
  • cta
    { label: string; href: string }
    Default: { label: "Get started", href: "#start" }
  • behavior

    hide: slides away while scrolling down, back on scrolling up. shrink: always visible, gets compact.

    "hide" | "shrink"
    Default: "hide"
  • threshold

    Scroll distance (px) after which the header turns compact and solid.

    number
    Default: 24
  • showProgress

    A thin reading-progress bar along the bottom edge.

    boolean
    Default: true
  • contained

    Follow the nearest scrollable ancestor instead of the window (e.g. inside a preview box).

    boolean
    Default: false
  • theme
    "dark" | "light"
    Default: "dark"
  • className
    string

FAQ

When does it hide?
With behavior="hide" it slides away once you scroll down past the first 120px, and comes back as soon as you scroll up even a little. It never hides while the mobile menu is open.
Does it work inside a scrolling panel?
Yes. Set contained and it listens to the nearest scrollable ancestor instead of the window, which is how the preview works.
What happens on phones?
When the header itself is narrower than 640px, the links and button fold into a menu that opens below the bar.

More Layout components

Section Container
Free
Bento Grid
Free
Shape Divider
Free
Masonry Grid
Free
Fieldset
Free
Panel
Free