React Animated Navbar with a Hover Pill That Slides Between Links

Pro

The smallest navbar in the set: logo and four links on the left, Sign in and a black Sign up button on the right, a hairline border underneath. Move the pointer along the links and a rounded grey highlight slides from one to the next instead of blinking on and off.

One small animation doing the work

Navbar with Hover Pill Links is a React and Tailwind CSS navbar with an animated hover effect: a pill shaped background that travels between menu items using Framer Motion's shared layout animation. It is a sticky top bar for Next.js or any React project and renders nothing but the nav itself.

Most hover effects on links are colour changes, which tell you what is under the pointer but nothing about where it just was. A highlight that moves gives the row a sense of continuity, the same idea operating systems use for selection in tab bars, and it makes a plain four link header feel built rather than defaulted.

Unlike the other navbars here, this one has no demo hero, no heading level prop and no dropdowns. Drop it into a layout and the only thing on screen is your navigation.

What the minimal bar contains

Shared layout pill

The hovered link renders a motion span with layoutId minimal-nav-hover. When the pointer moves on, Framer Motion animates that same element to the new link with a spring of stiffness 500 and damping 35.

Real anchors

Links are anchor elements, so they route, open in new tabs and are crawlable without changes.

Inverting button

Sign up is near black with white text in light mode and flips to white with dark text in dark mode, so it stays the strongest element in both.

Always on border

A one pixel bottom border is present from the start. Scrolling past 8px only swaps the solid fill for a 96 percent one with a light blur.

Animated menu icon

Three motion bars rotate into an X, and the drawer slides open with the links and the Sign up button.

When less header is better

Use it when

  • Your site has four or five top level pages and no sub menus.
  • You want a header that looks finished on day one with no file edits beyond your links and logo.
  • Docs, blogs and dashboards where the header should stay quiet and readable.
  • You like a hint of motion but not entrance animations or glass effects.

Skip it when

  • You need dropdowns or grouped links. Choose one of the mega menu navbars instead.
  • Most of your visitors are on touch screens, where the hover pill never appears.
  • You render two copies of this navbar on one page, since both would share the same layoutId and the pill could jump between them.
  • Sign in is important on phones, because the drawer only repeats Sign up.

Install it and pass four props

Everything visible is a prop: the logo, the brand name and its link, the links array and the two actions. Because there is no demo content and no hardcoded route, this is the one navbar here you can install and use without opening the file.

To recolour the pill, edit bg-[#f3f3f3] and dark:bg-white/[0.08] on the motion span. To keep the pill on the current page when the pointer leaves, initialise the active state from your router path instead of null and reset to it in onMouseLeave.

npx wensity@latest add navbar-with-hover-pill-links --type block
page.tsx
import { MinimalNavbar } from "@/components/wensity/blocks/navbar-with-hover-pill-links";
export function Header() {
return (
<MinimalNavbar
brandName="Quillnote"
brandHref="/"
links={[
{ label: "Features", href: "/features" },
{ label: "Templates", href: "/templates" },
{ label: "Changelog", href: "/changelog" },
{ label: "Pricing", href: "/pricing" },
]}
secondaryCta={{ label: "Log in", href: "/login" }}
cta={{ label: "Get Quillnote", href: "/signup" }}
/>
);
}

Props

PropTypeDefaultDescription
links{ label: string; href: string }[]Product, Pricing, Docs, BlogThe entries the pill slides between. Short labels keep the movement crisp.
logoReactNode-Replaces the ringed sample mark.
brandNamestring"Horizon"Text beside the mark and the accessible name of the brand link.
brandHrefstring"#"Where the brand link goes. Set it to / on a real site.
cta{ label: string; href: string }Sign upThe inverting button, also shown in the drawer.
secondaryCta{ label: string; href: string }Sign inText link shown from 768px up only.

Behaviour details worth knowing

Pointer only highlight

The pill follows mouseenter and mouseleave. Tabbing through the links shows the browser focus ring but does not move the pill. Add onFocus and onBlur that set the same state if you want keyboard parity.

Scroll style on load

The scroll handler is attached but not run on mount, so a page that reloads halfway down shows the unscrolled fill until the first scroll event. Call the handler once inside the effect to fix it.

Reduced motion

The pill spring and the icon morph ignore prefers-reduced-motion. MotionConfig with reducedMotion set to user turns the pill movement into an instant swap.

Smallest footprint

About 170 lines with Framer Motion as the only animation dependency, one scroll listener and no timers.

Block details

Navbar With Hover Pill Links
Category
Navbars
Renders
JavaScript animation. Paints first, then animates
Theme
Follows the site theme in light and dark
Dependencies
clsxframer-motiontailwind-merge
Source
170 lines, 7 KB in one file
Install
wensity add navbar-with-hover-pill-links --type block
Tags
light, dark, minimal, sticky, mobile-ready
Last updated

Quiet blocks that match a minimal header