React + MotionNavigation

Icon category bar

Categories shown as icons with labels, and an underline that slides across to the one you pick.

Settings

Code

import { useState } from "react";
import { motion } from "framer-motion";
import { Calendar, Compass, Home, Layers } from "lucide-react";

const spring = { type: "spring" as const, stiffness: 300, damping: 30 };

const ITEMS = [
  { icon: Home, label: "Homes" },
  { icon: Compass, label: "Nature" },
  { icon: Calendar, label: "Getaways" },
  { icon: Layers, label: "Design" },
];

interface CategoryBarProps {
  color?: string;
}

export default function CategoryBar({ color = "#0071e3" }: CategoryBarProps) {
  const [active, setActive] = useState(0);

  return (
    <div className="flex gap-7 border-b border-black/10 dark:border-white/10">
      {ITEMS.map(({ icon: Icon, label }, i) => (
        <button
          key={label}
          type="button"
          aria-pressed={active === i}
          onClick={() => setActive(i)}
          className="relative flex flex-col items-center gap-1.5 pb-3 text-xs text-[#86868b]"
        >
          <Icon className="h-5 w-5" style={{ color: active === i ? color : undefined }} />
          <span>{label}</span>
          {active === i && (
            <motion.i
              layoutId="cat-line"
              className="absolute inset-x-0 -bottom-px h-0.5"
              style={{ backgroundColor: color }}
              transition={spring}
            />
          )}
        </button>
      ))}
    </div>
  );
}

Prompt for AI

Paste it into ChatGPT, Claude or Cursor and it will adapt the block to your project with these settings, even if you don’t use React.

More in Navigation

Where to use it

Rental and marketplace sites use this pattern to let people browse by type before they search: cabins, beach houses, city breaks, design stays. It also works for a shop with product families or a recipe site sorted by meal. The sliding underline makes the choice clear, and the icon category bar reads well even at a glance.

Choose icons that really match each label, and keep the labels to one word. With more than six or seven categories, let the bar scroll sideways on mobile instead of squeezing everything into one line.