Components

Navbar

A floating, glassy React navbar built with Motion and Tailwind CSS that hides when you scroll down and reappears when you scroll up. A pill glides to the active link, a hover highlight slides between links, and on narrow layouts it becomes an animated mobile menu — all keyboard accessible.

  • Hide on scroll
  • Motion layoutId pill
  • Animated mobile menu
  • Container queries
  • Scroll container support
  • prefers-reduced-motion

Overview

Scroll down and the navbar slides away to give the content room; scroll up a little and it drops right back. Click a link and the pill glides over.

Features

Scroll down and the navbar slides away to give the content room; scroll up a little and it drops right back. Click a link and the pill glides over.

Pricing

Scroll down and the navbar slides away to give the content room; scroll up a little and it drops right back. Click a link and the pill glides over.

Changelog

Scroll down and the navbar slides away to give the content room; scroll up a little and it drops right back. Click a link and the pill glides over.

Installation

$ npx shadcn@latest add https://duskui.com/r/floating-navbar.json

It is sticky top-0 by default; override with className (e.g. fixed inset-x-0). It collapses below a 42rem container width using a Tailwind container query, so it adapts to the space it's given rather than the viewport.

Usage

site-header.tsx
"use client"

import Link from "next/link"
import { usePathname } from "next/navigation"
import { FloatingNavbar } from "@/components/dusk/navbar/floating-navbar"

const links = [
  { label: "Home", href: "/" },
  { label: "Docs", href: "/docs" },
  { label: "Pricing", href: "/pricing" },
]

export function SiteHeader() {
  const pathname = usePathname()
  return (
    <FloatingNavbar
      links={links}
      activeHref={pathname}
      linkAs={Link}
      logo={<Link href="/">Acme</Link>}
    />
  )
}

Examples

Mobile menu

In a narrow container the links move into a menu. The button morphs into a close icon, the panel springs open with its links cascading in, and it closes on Escape (returning focus), on an outside click or when a link is chosen. The navbar won't hide while the menu is open.

Open the menu, then scroll.

Always visible

hideOnScroll={false} keeps it in place — useful for short pages. Put buttons on the right with actions; they stay visible at every size.

API Reference

Also accepts any div prop for the sticky wrapper.

PropTypeDefaultDescription
links{ label: string; href: string }[]—The navigation links.
activeHrefstring—Controlled active link, e.g. usePathname().
defaultActiveHrefstringfirst linkUncontrolled initial active link; clicking a link activates it.
onNavigate(href, event) => void—Called on link click. Call event.preventDefault() to handle navigation yourself.
logo / actionsReactNode—Brand on the left and buttons on the right.
containerRefObject<HTMLElement>—Scroll container to watch. Defaults to the page.
hideOnScrollbooleantrueHide on scroll down, show on scroll up.
revealAtnumber64Always shown above this scroll offset, in px.
thresholdnumber8Scroll distance in one direction before toggling, in px.
linkAsElementType"a"Link component, e.g. Next.js Link.
aria-labelstring"Main"Names the navigation landmark.

Accessibility

  • Links live in a header › nav landmark (labelled “Main” by default) as a list; the active one carries aria-current="page".
  • Keyboard focus anywhere in the navbar reveals it instantly, so a hidden bar can never trap focus off-screen.
  • The menu button exposes aria-expanded and aria-controls, switches its label between “Open menu” and “Close menu”, and Escape closes the menu and returns focus to it.
  • The gliding pill and hover highlight are decorative and aria-hidden; hover effects only follow a mouse.
  • Under prefers-reduced-motion the bar fades out and in instead of sliding, and the menu only fades.