Navbar
A responsive navigation header positioned on top side of your page that includes support for branding, links, navigation, collapse menu and more.
Installation
The above command is for individual installation only. You may skip this step if @heroui/react is already installed globally.
Import
HeroUI exports 7 navbar-related components:
- Navbar: The main component of navbar.
- NavbarBrand: The component for branding.
- NavbarContent: The component for wrapping navbar items.
- NavbarItem: The component for navbar item.
- NavbarMenuToggle: The component for toggling navbar menu.
- NavbarMenu: The component for wrapping navbar menu items.
- NavbarMenuItem: The component for navbar menu item.
Usage
Static
You can use the position prop to make the navbar static positioned (the default behavior is sticky).
Hide on scroll
It is possible to hide the navbar on scroll by using the shouldHideOnScroll prop.
With Menu
You can use the NavbarMenuToggle and NavbarMenu components to display a togglable menu.
If you want to remove the open / close animation, you can pass the disableAnimation={true} prop to Navbar component.
Controlled Menu
You can use the isMenuOpen and onMenuOpenChange props to control the navbar menu state.
With Border
You can use the isBordered prop to add a bottom border to the navbar.
Disabling Blur
Navbar has a blur effect by default. You can disable it by using the isBlurred=false prop.
With Dropdown Menu
It is possible to use the Dropdown component to display a dropdown menu as navbar item.
With Avatar
Example of a navbar with avatar and dropdown menu.
With Search Input
Example of a navbar with search input.
Customizing the active item
When the NavbarItem is active, it will have a data-active attribute. You can use this attribute to customize it.
Slots
- base: The main slot for the navbar. It takes the full width of the parent and wraps the navbar elements including the menu.
- wrapper: The slot that contains the navbar elements such as
brand,contentandtoggle. - brand: The slot for the
NavbarBrandcomponent. - content: The slot for the
NavbarContentcomponent. - item: The slot for the
NavbarItemcomponent. - toggle: The slot for the
NavbarMenuTogglecomponent. - toggleIcon: The slot for the
NavbarMenuToggleicon. - menu: The slot for the
NavbarMenucomponent. - menuItem: The slot for the
NavbarMenuItemcomponent.
Data Attributes
Navbar has the following attributes on the base element:
- data-menu-open: Indicates if the navbar menu is open.
- data-hidden:
Indicates if the navbar is hidden. It is used when the
shouldHideOnScrollprop istrue.
NavbarContent
- data-justify: The justify content of the navbar content. It takes into account the correct space distribution.
NavbarItem has the following attributes on the base element:
- data-active:
Indicates if the navbar item is active. It is used when the
isActiveprop istrue.
NavbarMenuToggle has the following attributes on the base element:
- data-open:
Indicates if the navbar menu is open. It is used when the
isMenuOpenprop istrue. - data-pressed: When the navbar menu toggle is pressed. Based on usePress
- data-hover: When the navbar menu toggle is being hovered. Based on useHover
- data-focus-visible: When the navbar menu toggle is being focused with the keyboard. Based on useFocusRing.
NavbarMenuItem has the following attributes on the base element:
- data-active:
Indicates if the menu item is active. It is used when the
isActiveprop istrue.
API
Navbar Props
| Prop | Type | Default |
children* | | |
height | | "4rem (64px)" |
position | | "sticky" |
maxWidth | | "lg" |
parentRef | | "window" |
isBordered | | false |
isBlurred | | true |
isMenuOpen | | false |
isMenuDefaultOpen | | false |
shouldHideOnScroll | | false |
motionProps | | |
disableScrollHandler | | false |
disableAnimation | | false |
classNames | |
Navbar Events
| Prop | Type | Default |
onMenuOpenChange | | |
onScrollPositionChange | |
NavbarContent Props
| Prop | Type | Default |
children* | | |
justify | | "start" |
NavbarItem Props
| Prop | Type | Default |
children | | |
isActive | | false |
NavbarMenuToggle Props
| Prop | Type | Default |
icon | | |
isSelected | | false |
defaultSelected | | false |
srOnlyText | | "open/close navigation menu" |
NavbarMenuToggle Events
| Prop | Type | Default |
onChange | |
NavbarMenu Props
| Prop | Type | Default |
children* | | |
portalContainer | | "document.body" |
motionProps | |
NavbarMenuItem Props
| Prop | Type | Default |
children | | |
isActive | | false |

