Back to library
INTERACTION_119

Expanding Navigation Pill.

A pill indicator glides between nav items. Sized and positioned to the active link before the trigger; animating the pill's translate and width to the target link once hover or active route change.

CATEGORY
Navigation
COMPLEXITY
Easy
TECH
CSS
PLATFORM
Both
PERFORMANCE
Light
LIVE PLAYGROUND
HomeWorkPricing
CSS / CSS
/* Expanding Navigation Pill — A pill indicator glides between nav items. */
.expanding-navigation-pill {
  --dur: 380ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --stagger: 60ms;
  will-change: transform, opacity;
}

.expanding-navigation-pill > * {
  opacity: 0;
  transform: translateY(14px);
  animation: expanding-navigation-pill-in var(--dur) var(--ease) forwards;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}

/* sized and positioned to the active link -> animating the pill's translate and width to the target link */
@keyframes expanding-navigation-pill-in {
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .expanding-navigation-pill > * {
    opacity: 1;
    transform: none;
    animation: none;
  }
}
React / TSX
import { useEffect, useRef } from "react";

/** Expanding Navigation Pill — trigger: hover or active route change */
export function ExpandingNavigationPill({ children }: { children: React.ReactNode }) {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
      el.dataset["state"] = "in";
      return;
    }
    const io = new IntersectionObserver(
      ([entry]) => {
        if (entry?.isIntersecting) {
          el.dataset["state"] = "in";
          io.unobserve(el);
        }
      },
      { threshold: 0.2 },
    );
    io.observe(el);
    return () => io.disconnect();
  }, []);

  return (
    <div ref={ref} className="expanding-navigation-pill" data-state="out">
      {children}
    </div>
  );
}

IF YOU LIKE THIS, STEAL THESE TOO.

DISCOVEREFFECTSPROMPTS
INTERACTION_027CSS

Navigation Underline

Underline grows from the origin side on hover.

Navigation / LightView
Home
Work
Pricing
INTERACTION_117CSS

Animated Mobile Menu

The panel slides in and links cascade behind it.

Navigation / LightView
HomeWorkPricing
INTERACTION_120CSS

Active Link Indicator

A rule wipes in under the hovered link and stays on the active route.

Navigation / LightView
HomeWorkPricing
INTERACTION_121CSS

Scroll Aware Navbar

The header hides on scroll down and returns on scroll up.

Navigation / LightView