Back to PrequelUIYou are on Bottom Navigation.

Bottom Navigation

A bottom bar with a gliding highlight that recedes on scroll.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
bottom-navigation.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/bottom-navigation.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/bottom-navigation.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
bottom-navigation.tsx
"use client";

import * as React from "react";
import { motion } from "motion/react";
import { cn } from "@/lib/utils";
import { selectionSpring, useReduceMotion } from "./motion";

type BottomNavContextValue = {
  value: string;
  setValue: (value: string) => void;
  id: string;
};

const BottomNavContext = React.createContext<BottomNavContextValue | null>(null);

function useBottomNav(component: string) {
  const context = React.useContext(BottomNavContext);
  if (!context) throw new Error(`${component} must be used inside <BottomNavigation>.`);
  return context;
}

export type BottomNavigationProps = React.HTMLAttributes<HTMLElement> & {
  value?: string;
  defaultValue?: string;
  onValueChange?: (value: string) => void;
  hideOnScroll?: boolean;
};

export function BottomNavigation({
  value: valueProp,
  defaultValue = "",
  onValueChange,
  hideOnScroll = false,
  className,
  children,
  ...props
}: BottomNavigationProps) {
  const [internal, setInternal] = React.useState(defaultValue);
  const [hidden, setHidden] = React.useState(false);
  const controlled = valueProp !== undefined;
  const value = controlled ? valueProp : internal;
  const id = React.useId().replace(/:/g, "");
  const reduce = useReduceMotion();
  const lastY = React.useRef(0);

  const setValue = React.useCallback(
    (next: string) => {
      if (!controlled) setInternal(next);
      onValueChange?.(next);
    },
    [controlled, onValueChange],
  );

  React.useEffect(() => {
    if (!hideOnScroll) return;
    const onScroll = () => {
      const y = window.scrollY;
      setHidden(y > 24 && y > lastY.current);
      lastY.current = y;
    };
    window.addEventListener("scroll", onScroll, { passive: true });
    return () => window.removeEventListener("scroll", onScroll);
  }, [hideOnScroll]);

  return (
    <BottomNavContext.Provider value={{ value, setValue, id }}>
      <motion.nav
        data-slot="bottom-navigation"
        animate={{ y: hidden && !reduce ? 110 : 0 }}
        transition={selectionSpring}
        className={cn(
          "flex w-full max-w-[340px] items-center justify-between gap-1 rounded-2xl border bg-background p-1.5 shadow-sm",
          className,
        )}
        {...(props as Record<string, unknown>)}
      >
        {children}
      </motion.nav>
    </BottomNavContext.Provider>
  );
}

export type BottomNavigationItemProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
  value: string;
  icon?: React.ReactNode;
  label: string;
};

export function BottomNavigationItem({
  value,
  icon,
  label,
  className,
  onClick,
  ...props
}: BottomNavigationItemProps) {
  const nav = useBottomNav("BottomNavigationItem");
  const active = nav.value === value;
  return (
    <button
      type="button"
      aria-current={active ? "page" : undefined}
      data-state={active ? "active" : "inactive"}
      onClick={(event) => {
        onClick?.(event);
        if (!event.defaultPrevented) nav.setValue(value);
      }}
      className={cn(
        "relative flex h-12 flex-1 flex-col items-center justify-center gap-0.5 rounded-xl outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40",
        active ? "text-foreground" : "text-muted-foreground hover:text-foreground",
        className,
      )}
      {...props}
    >
      {active ? (
        <motion.span
          layoutId={`${nav.id}-highlight`}
          className="absolute inset-0 rounded-xl bg-accent"
          transition={selectionSpring}
          aria-hidden="true"
        />
      ) : null}
      <span className="relative flex items-center justify-center [&_svg]:size-4">{icon}</span>
      <span className="relative text-[13px] font-medium">{label}</span>
    </button>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/bottom-navigation.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

bottom-navigation.tsx
import {
  BottomNavigation,
  BottomNavigationItem,
} from "@/components/prequelui/bottom-navigation";
import { Home, Compass, Bell, User } from "lucide-react";

export default function Demo() {
  return (
    <BottomNavigation defaultValue="home">
      <BottomNavigationItem value="home" label="Home" icon={<Home />} />
      <BottomNavigationItem value="explore" label="Explore" icon={<Compass />} />
      <BottomNavigationItem value="alerts" label="Alerts" icon={<Bell />} />
      <BottomNavigationItem value="you" label="You" icon={<User />} />
    </BottomNavigation>
  );
}
import { BottomNavigation } from "@/components/prequelui/bottom-navigation";

export function Variant() {
  return (
    <BottomNavigation tempo={1.2}>
      …
    </BottomNavigation>
  );
}
03

Animation

One highlight is shared by every item, so switching sections slides the same surface instead of fading one out and another in. Scrolling down lets the bar recede; scrolling up brings it back.

  • Highlight spring: 300 / 30 on position and size.
  • Recede: the bar translates by 110% on the same spring family.
  • Touch and keyboard selection both retarget the shared node.
  • `hideOnScroll` can be turned off when the bar is inline.
  • Reduced motion removes the slide and keeps the colour state.
spring 300 / 30shared highlightrecede 110%scroll aware
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

BottomNavigation

PropTypeDefault
valuestring—
defaultValuestring""
onValueChange(value: string) => void—
hideOnScrollbooleanfalse
classNamestring—

BottomNavigationItem

PropTypeDefault
valuestring—
labelstring—
iconReactNode—
classNamestring—

Next component

Cursor

A custom cursor and a trailing label with two different springs.