Navbar
A horizontal navigation bar component with semantic slots for organizing logos, navigation links, and action buttons.Build consistent navigation experiences with semantic slots for logo, navigation, and actions. The Navbar component provides a flexible foundation for headers that work across all screen sizes.
Built with compound components for maximum flexibility—compose Logo, Navigation, and Actions slots to create any navbar layout.
Installation
Usage
Anatomy
The Navbar is a compound component with four parts:
Props
Root
Logo, Navigation, Actions
All slot components extend FlexProps and support all Flex layout properties.
Examples
Basic Navbar
Simple navbar with logo and navigation links:
Marketing Navbar
Full marketing navbar with all slots populated:
Slot Architecture
Navbar acts as a layout container with three semantic slots. Each slot has a specific purpose and behavior. Visualize the slot boundaries to understand the layout:
With Icons
Add icons to navigation items for visual clarity:
With Next.js Link
Integrate with Next.js routing using asChild:
With User Menu
Dashboard navbar with dropdown user menu:
Minimal Logo Only
When you only need branding without navigation:
With Shell Layout
Combine Navbar with Shell for complete page layouts:
Position
Use the position prop to control how the navbar behaves when scrolling.
Fixed
Fixed navbars stay at the top of the viewport. Content scrolls beneath them. Add padding to your page content to prevent overlap.
Sticky
Sticky navbars scroll with content until they reach the top, then stick in place.
Static
Static navbars flow with the document and scroll out of view.
Size
Use the size prop to control navbar padding. Height is content-driven, adjusting automatically to fit your content.
Size 1
Compact padding for dense interfaces or mobile layouts.
Size 2
Standard padding for most applications. The default size.
Size 3
Spacious padding for prominent headers or when you want more breathing room.
Slots
Navbar exposes three semantic slots that handle layout automatically. Understanding slot behavior helps you build effective navigation.
Logo
The Logo slot is designed for brand identity elements. It never shrinks and stays left-aligned.
Navigation
The Navigation slot expands to fill available space and centers its content. Use it for primary navigation links.
Actions
The Actions slot is right-aligned and never shrinks. Use it for CTAs, user menus, and utility controls.
Polymorphism
AsChild
Use the asChild prop on any slot to merge its props with a child element. This is useful for custom wrappers or routing integration.
Accessibility
The Navbar component follows WAI-ARIA best practices for navigation landmarks.
Semantic Structure
Navbar.Rootrenders as a semantic<header>elementNavbar.Navigationrenders as a<nav>element withrole="navigation"- Proper heading hierarchy should be maintained within logo content
Keyboard Navigation
- All interactive elements within the navbar are keyboard accessible
- Focus order follows visual order: logo, navigation, actions
- Use Button or Link components for interactive elements to ensure proper focus handling
Screen Readers
- The
<header>landmark helps screen reader users identify the navigation area - The
<nav>element within Navigation slot provides additional context - Ensure all interactive elements have appropriate labels
Changelog
Changed
- Replaced
heightprop withsizeprop (1, 2, 3) for padding-based sizing - Height is now content-driven instead of fixed
- Slots now extend
FlexPropsfor full layout control (gap, align, justify, etc.)
Added
- Initial release with compound component architecture
- Semantic slots for Logo, Navigation, and Actions
- Position variants: fixed, sticky, static
- Size options: 1 (compact), 2 (default), 3 (spacious)
asChildprop for all slots using Radix Slot pattern- Responsive gap adjustments for mobile layouts
© 2026 Kushagra Dhawan. Licensed under MIT. GitHub.