Overview
Animated Tabs is a navigation component that provides smooth, fluid tab switching with motion-based animations. It offers two distinct visual variants: a default pill-style design with a sliding background highlight, and an underline variant with a moving bottom border.Key features
- Two animation variants (default and underline)
- Smooth spring-based transitions using Motion
- Automatic active state management
- Accessible button-based implementation
- Fully customizable styling with Tailwind CSS
When to use it
- Navigation between different content sections
- Settings panels with multiple categories
- Dashboard views with segmented controls
- Any interface requiring elegant tab switching
Installation
Usage
Basic example
Underline variant
Props
Array of tab labels to display. Each string becomes a selectable tab.
Visual style of the tabs:
default: Pill-style tabs with sliding background highlightunderline: Border-bottom tabs with moving underline indicator
Examples
Default variant with pill design
The default variant renders tabs in a compact, pill-shaped container with a sliding background that follows the active tab.Underline variant for navigation
The underline variant works well for top-level navigation with a more traditional tab appearance.Short tab list
Customization
Animation timing
The component uses spring-based animations with the following configuration:components/forgeui/animated-tabs.tsx:38-42 and components/forgeui/animated-tabs.tsx:75-79 to adjust the animation feel.
Styling
The component uses Tailwind CSS classes and CSS variables from your theme. Key customization points:- Active tab colors: Modify
text-primaryandbg-primaryclasses - Inactive tab colors: Adjust
text-muted-foregroundclasses - Container styling: Update the wrapper div classes for different shapes or shadows
- Tab spacing: Modify
px-4(underline) orpx-3(default) for horizontal padding
Layout ID
The
layoutId prop in Motion enables shared layout animations. Each variant uses a unique ID (active-tab-underline or active-tab-background) to prevent conflicts when using multiple instances.Component details
State management
The component maintains internal state for the active tab, defaulting to the first tab in the array:Motion layout animations
Both variants use Motion’slayoutId feature to create smooth transitions as the indicator moves between tabs. The initial={false} prop prevents animation on mount.