Navbar
React Bootstrap 5 Navbar component
Documentation and examples for powerful, responsive navigation header - MDB navbar. Includes support for branding, navigation, and more, including support for our collapse plugin.
Basic example
A basic example of the navbar with the most common elements like link, search form, brand, and dropdown. All of them are explained in detail in the supported content section.
Note: this example uses
color
(bg-light
) and
spacing
(my-2
, my-lg-0
, me-sm-0
, my-sm-0
) utility
classes.
import React, { useState } from 'react';
import {
MDBContainer,
MDBNavbar,
MDBNavbarBrand,
MDBNavbarToggler,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBBtn,
MDBDropdown,
MDBDropdownToggle,
MDBDropdownMenu,
MDBDropdownItem,
MDBCollapse,
} from 'mdb-react-ui-kit';
export default function App() {
const [openBasic, setOpenBasic] = useState(false);
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Brand</MDBNavbarBrand>
<MDBNavbarToggler
aria-controls='navbarSupportedContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenBasic(!openBasic)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openBasic}>
<MDBNavbarNav className='mr-auto mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBDropdown>
<MDBDropdownToggle tag='a' className='nav-link' role='button'>
Dropdown
</MDBDropdownToggle>
<MDBDropdownMenu>
<MDBDropdownItem link>Action</MDBDropdownItem>
<MDBDropdownItem link>Another action</MDBDropdownItem>
<MDBDropdownItem link>Something else here</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
<form className='d-flex input-group w-auto'>
<input type='search' className='form-control' placeholder='Type query' aria-label='Search' />
<MDBBtn color='primary'>Search</MDBBtn>
</form>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
);
}
How it works
Here’s what you need to know before getting started with the navbar:
-
Navbars require a wrapping
.navbar
with.navbar-expand{-sm|-md|-lg|-xl|-xxl}
for responsive collapsing and color scheme classes. - Navbars and their contents are fluid by default. Change the container to limit their horizontal width in different ways.
- Use our spacing and flex utility classes for controlling spacing and alignment within navbars.
- Navbars are responsive by default, but you can easily modify them to change that. Responsive behavior depends on our Collapse JavaScript plugin.
-
Ensure accessibility by using a
<nav>
element or, if using a more generic element such as a<div>
, add arole="navigation"
to every navbar to explicitly identify it as a landmark region for users of assistive technologies. -
Indicate the current item by using
aria-current="page"
for the current page oraria-current="true"
for the current item in a set.
Supported content
Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
.navbar-brand
for your company, product, or project name.-
.navbar-nav
for a full-height and lightweight navigation (including support for dropdowns). -
.navbar-toggler
for use with our collapse plugin and other navigation toggling behaviors. - Flex and spacing utilities for any form controls and actions.
.navbar-text
for adding vertically centered strings of text.-
.collapse.navbar-collapse
for grouping and hiding navbar contents by a parent breakpoint.
Apart from listed above, navbar supports also components like breadcrumbs, forms, buttons, icons, flags, avatars, badges, and a few more.
Brand
The .navbar-brand
can be applied to most elements, but an anchor works best as
some elements might require utility classes or custom styles.
import React from 'react';
import {
MDBContainer,
MDBNavbar,
MDBNavbarBrand
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
<br />
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand tag="span" className='mb-0 h1'>Navbar</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
Adding images to the .navbar-brand
will likely always require custom styles or
utilities to properly size. Here are some examples to demonstrate.
import React from 'react';
import {
MDBContainer,
MDBNavbar,
MDBNavbarBrand
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar light bgColor='light'>
<MDBContainer>
<MDBNavbarBrand href='#'>
<img
src='https://mdbootstrap.com/img/logo/mdb-transaprent-noshadows.webp'
height='30'
alt=''
loading='lazy'
/>
</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
import React from 'react';
import {
MDBContainer,
MDBNavbar,
MDBNavbarBrand
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>
<img
src='https://mdbootstrap.com/img/logo/mdb-transaprent-noshadows.webp'
height='30'
alt=''
loading='lazy'
/>
MDBootstrap
</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
Forms
Place various form controls and components within a navbar:
import React from 'react';
import {
MDBContainer,
MDBNavbar,
MDBBtn,
MDBInputGroup
} from 'mdb-react-ui-kit';
export default function App() {
return (
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<MDBInputGroup tag="form" className='d-flex w-auto mb-3'>
<input className='form-control' placeholder="Type query" aria-label="Search" type='Search' />
<MDBBtn outline>Search</MDBBtn>
</MDBInputGroup>
</MDBContainer>
</MDBNavbar>
);
}
Immediate children elements in .navbar
use flex layout and will default to
justify-content: space-between
. Use additional
flex utilities as needed to adjust this behavior.
import React from 'react';
import {
MDBContainer,
MDBNavbar,
MDBNavbarBrand,
MDBBtn
} from 'mdb-react-ui-kit';
export default function App() {
return (
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand>Navbar</MDBNavbarBrand>
<MDBInputGroup tag="form" className='d-flex w-auto mb-3'>
<input className='form-control' placeholder="Type query" aria-label="Search" type='Search' />
<MDBBtn outline>Search</MDBBtn>
</MDBInputGroup>
</MDBContainer>
</MDBNavbar>
);
}
White form for dark theme.
import React from 'react';
import {
MDBContainer,
MDBNavbar,
MDBBtn,
MDBInputGroup
} from 'mdb-react-ui-kit';
export default function App() {
return (
<MDBNavbar dark bgColor='dark'>
<MDBContainer fluid>
<MDBInputGroup tag="form" className='d-flex w-auto mb-3'>
<input className='form-control' placeholder="Type query" aria-label="Search" type='Search' />
<MDBBtn outline>Search</MDBBtn>
</MDBInputGroup>
</MDBContainer>
</MDBNavbar>
);
}
Text
Navbars may contain bits of text with the help of
.navbar-text
. This class adjusts vertical alignment and horizontal spacing for
strings of text.
import React from 'react';
import {
MDBNavbar,
MDBContainer
} from 'mdb-react-ui-kit';
export default function App() {
return (
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<span className='navbar-text'> Navbar text with an inline element </span>
</MDBContainer>
</MDBNavbar>
);
}
Mix and match with other components and utilities as needed.
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBNavbarToggler,
MDBCollapse
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavText, setOpenNavText] = useState(false);
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar w/ text</MDBNavbarBrand>
<MDBNavbarToggler
type='button'
data-target='#navbarText'
aria-controls='navbarText'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavText(!openNavText)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openNavText}>
<MDBNavbarNav className='mr-auto mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Features</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Pricing</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
<span className='navbar-text'> Navbar text with an inline element </span>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
);
}
Icons
Choose from hundreds of our icons and simply add them to the navbar.
Note: We add .d-flex .flex-row
classes to keep the icons
inline when the navbar is collapsed. Without this, they will stack one under another.
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink
} from 'mdb-react-ui-kit';
export default function App() {
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarNav className='d-flex flex-row'>
<MDBNavbarItem className='me-3 me-lg-0'>
<MDBNavbarLink href='#'>
<MDBIcon fas icon='shopping-cart' />
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem className='me-3 me-lg-0'>
<MDBNavbarLink href='#'>
<MDBIcon fab icon='twitter' />
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBContainer>
</MDBNavbar>
);
}
Badges
Badges can be very useful for presenting counters, for example in the shopping cart.
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBBadge
} from 'mdb-react-ui-kit';
export default function App() {
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarNav>
<MDBNavbarItem>
<MDBNavbarLink href='#'>
<MDBBadge pill color='danger'>!</MDBBadge>
<span>
<MDBIcon fas icon='shopping-cart'></MDBIcon>
</span>
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBContainer>
</MDBNavbar>
);
}
Content alignment
To align navbar content to the right or left use
me-auto
or ms-auto
classes. For content centering use
flexbox utilities.
Left aligned
Add .me-auto
class next to the .navbar-nav
to align the content to
the left.
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBNavbarToggler,
MDBCollapse,
MDBDropdown,
MDBDropdownMenu,
MDBDropdownToggle,
MDBDropdownItem,
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavLeft, setOpenNavLeft] = useState(false);
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarLeftAlignExample'
aria-controls='navbarLeftAlignExample'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavLeft(!openNavLeft)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openNavLeft}>
<MDBNavbarNav className='me-auto mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBDropdown>
<MDBDropdownToggle tag='a' className='nav-link'>
Dropdown
</MDBDropdownToggle>
<MDBDropdownMenu>
<MDBDropdownItem link>Action</MDBDropdownItem>
<MDBDropdownItem link>Another action</MDBDropdownItem>
<MDBDropdownItem link>Something else here</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
);
}
Right aligned
Add .ms-auto
class next to the .navbar-nav
to align the content to
the right.
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBNavbarToggler,
MDBCollapse,
MDBDropdown,
MDBDropdownMenu,
MDBDropdownToggle,
MDBDropdownItem,
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavRight, setOpenNavRight] = useState(false);
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarRightAlignExample'
aria-controls='navbarRightAlignExample'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavRight(!openNavRight)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openNavRight}>
<MDBNavbarNav right fullWidth={false} className='mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBDropdown>
<MDBDropdownToggle tag='a' className='nav-link'>
Dropdown
</MDBDropdownToggle>
<MDBDropdownMenu>
<MDBDropdownItem link>Action</MDBDropdownItem>
<MDBDropdownItem link>Another action</MDBDropdownItem>
<MDBDropdownItem link>Something else here</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
);
}
Centered
Remove .ms-auto
or .me-auto
class and add
.justify-content-center
next to the .navbar-collapse
to center the
content.
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBNavbarToggler,
MDBCollapse,
MDBDropdown,
MDBDropdownMenu,
MDBDropdownToggle,
MDBDropdownItem,
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavCentred, setOpenNavCentred] = useState(false);
return (
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarCenteredExample'
aria-controls='navbarCenteredExample'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavCentred(!openNavCentred)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openNavCentred} center id='navbarCenteredExample'>
<MDBNavbarNav fullWidth={false} className='mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBDropdown>
<MDBDropdownToggle tag='a' className='nav-link'>
Dropdown
</MDBDropdownToggle>
<MDBDropdownMenu>
<MDBDropdownItem link>Action</MDBDropdownItem>
<MDBDropdownItem link>Another action</MDBDropdownItem>
<MDBDropdownItem link>Something else here</MDBDropdownItem>
</MDBDropdownMenu>
</MDBDropdown>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
);
}
Colors
Theming the navbar has never been easier thanks to the combination of theming classes and
background-color
utilities. Choose from .navbar-light
for use with
light background colors, or .navbar-dark
for dark background colors. Then,
customize with .bg-*
utilities.
See also our color docs to learn more about colors.
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBIcon,
MDBNavbarNav,
MDBNavbarItem,
MDBNavbarLink,
MDBNavbarToggler,
MDBNavbarBrand,
MDBCollapse
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavColor, setOpenNavColor] = useState(false);
const [openNavColorSecond, setOpenNavColorSecond] = useState(false);
const [openNavColorThird, setOpenNavColorThird] = useState(false);
return (
<>
<MDBNavbar expand='lg' dark bgColor='primary'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
<MDBNavbarToggler
type='button'
data-target='#navbarColor02'
aria-controls='navbarColor02'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavColor(!openNavColor)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse open={openNavColor} navbar>
<MDBNavbarNav className='me-auto mb-2 mb-lg-0'>
<MDBNavbarItem className='active'>
<MDBNavbarLink aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Features</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Pricing</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>About</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
<br />
<MDBNavbar expand='lg' dark bgColor='dark'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
<MDBNavbarToggler
type='button'
data-target='#navbarColor02'
aria-controls='navbarColor02'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavColorSecond(!openNavColorSecond)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse open={openNavColorSecond} navbar id='navbarColor02'>
<MDBNavbarNav className='me-auto mb-2 mb-lg-0'>
<MDBNavbarItem className='active'>
<MDBNavbarLink aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Features</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Pricing</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>About</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
<br />
<MDBNavbar expand='lg' light style={{ backgroundColor: '#e3f2fd' }}>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
<MDBNavbarToggler
type='button'
data-target='#navbarColor02'
aria-controls='navbarColor02'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavColorThird(!openNavColorThird)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse open={openNavColorThird} navbar>
<MDBNavbarNav className='me-auto mb-2 mb-lg-0'>
<MDBNavbarItem className='active'>
<MDBNavbarLink aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Features</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Pricing</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>About</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
</>
);
}
Containers
Although it’s not required, you can wrap a navbar in a
MDBContainer
to center it on a page or add one within to only center the contents
of a fixed or static top navbar. Note that an inner container
is still required.
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBContainer>
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</MDBContainer>
</>
);
}
Use any of the responsive containers to change how wide the content in your navbar.
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer size="md">
<MDBNavbarBrand href="#">Navbar</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
Placement
Use our
position utilities to place navbars in
non-static positions. Choose from fixed to the top, fixed to the bottom, or stickied to the
top (scrolls with the page until it reaches the top, then stays there). Fixed navbars use
position: fixed
, meaning they’re pulled from the normal flow of the DOM and may
require custom CSS (e.g., padding-top
on the <body>
) to
prevent overlap with other elements.
Also note that
.sticky-top
uses position: sticky
, which
isn’t fully supported in every browser.
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Default</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar fixed='top' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Fixed top</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar fixed='bottom' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Fixed bottom</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
import React from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
} from 'mdb-react-ui-kit';
export default function App() {
return (
<>
<MDBNavbar sticky light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Sticky top</MDBNavbarBrand>
</MDBContainer>
</MDBNavbar>
</>
);
}
Responsive behaviors
Navbars can utilize .navbar-toggler
, .navbar-collapse
, and
.navbar-expand{-sm|-md|-lg|-xl|-xxl}
classes to change when their content
collapses behind a button. In combination with other utilities, you can easily choose when to
show or hide particular elements.
For navbars that never collapse, add the
.navbar-expand
class on the navbar. For navbars that always collapse, don’t add
any .navbar-expand
class.
Toggler
Navbar togglers are left-aligned by default, but should they follow a sibling element like a
.navbar-brand
, they’ll automatically be aligned to the far right. Reversing
your markup will reverse the placement of the toggler. Below are examples of different
toggle styles.
With no .navbar-brand
shown in lowest breakpoint:
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
MDBNavbarToggler,
MDBNavbarItem,
MDBNavbarLink,
MDBCollapse,
MDBBtn,
MDBIcon,
MDBNavbarNav,
MDBInputGroup
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavNoToggler, setOpenNavNoToggler] = useState(false);
return (
<>
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarTogglerDemo01'
aria-controls='navbarTogglerDemo01'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavNoToggler(!openNavNoToggler)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openNavNoToggler}>
<MDBNavbarBrand href='#'>Hidden brand</MDBNavbarBrand>
<MDBNavbarNav className='mr-auto mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
<MDBInputGroup tag="form" className='d-flex w-auto mb-3'>
<input className='form-control' placeholder="Type query" aria-label="Search" type='Search' />
<MDBBtn outline>Search</MDBBtn>
</MDBInputGroup>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
</>
);
}
With a brand name shown on the left and toggler on the right:
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
MDBNavbarToggler,
MDBNavbarItem,
MDBNavbarLink,
MDBCollapse,
MDBBtn,
MDBIcon,
MDBNavbarNav,
MDBInputGroup
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavNoTogglerSecond, setOpenNavNoTogglerSecond] = useState(false);
return (
<>
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
<MDBNavbarToggler
type='button'
data-target='#navbarTogglerDemo02'
aria-controls='navbarTogglerDemo02'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavNoTogglerSecond(!openNavNoTogglerSecond)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBCollapse navbar open={openNavNoTogglerSecond}>
<MDBNavbarNav className='mr-auto mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
<MDBInputGroup tag="form" className='d-flex w-auto mb-3'>
<input className='form-control' placeholder="Type query" aria-label="Search" type='Search' />
<MDBBtn outline>Search</MDBBtn>
</MDBInputGroup>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
</>
);
}
With a toggler on the left and brand name on the right:
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
MDBNavbarToggler,
MDBNavbarItem,
MDBNavbarLink,
MDBCollapse,
MDBBtn,
MDBNavbarNav,
MDBIcon,
MDBInputGroup
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavNoTogglerThird, setOpenNavNoTogglerThird] = useState(false);
return (
<>
<MDBNavbar expand='lg' light bgColor='light'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarTogglerDemo03'
aria-controls='navbarTogglerDemo03'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavNoTogglerThird(!openNavNoTogglerThird)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
<MDBNavbarBrand href='#'>Navbar</MDBNavbarBrand>
<MDBCollapse navbar open={openNavNoTogglerThird}>
<MDBNavbarNav className='mr-auto mb-2 mb-lg-0'>
<MDBNavbarItem>
<MDBNavbarLink active aria-current='page' href='#'>
Home
</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink href='#'>Link</MDBNavbarLink>
</MDBNavbarItem>
<MDBNavbarItem>
<MDBNavbarLink disabled href='#' tabIndex={-1} aria-disabled='true'>
Disabled
</MDBNavbarLink>
</MDBNavbarItem>
</MDBNavbarNav>
<MDBInputGroup tag="form" className='d-flex w-auto mb-3'>
<input className='form-control' placeholder="Type query" aria-label="Search" type='Search' />
<MDBBtn outline>Search</MDBBtn>
</MDBInputGroup>
</MDBCollapse>
</MDBContainer>
</MDBNavbar>
</>
);
}
External content
Sometimes you want to use the collapse plugin to trigger hidden content elsewhere on the
page. Because our plugin works on the
id
and data-mdb-target
matching, that’s easily done!
import React, { useState } from 'react';
import {
MDBNavbar,
MDBContainer,
MDBNavbarBrand,
MDBNavbarToggler,
MDBNavbarItem,
MDBNavbarLink,
MDBIcon,
MDBCollapse
} from 'mdb-react-ui-kit';
export default function App() {
const [openNavExternal, setOpenNavExternal] = useState(false);
return (
<>
<MDBCollapse open={openNavExternal}>
<div className='bg-dark p-4'>
<h5 className='text-white h4'>Collapsed content</h5>
<span className='text-muted'>Toggleable via the navbar brand.</span>
</div>
</MDBCollapse>
<MDBNavbar dark bgColor='dark'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setOpenNavExternal(!openNavExternal)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
</>
);
}
Navbar - API
Import
import {
MDBNavbar,
MDBNavbarBrand,
MDBNavbarBrand,
MDBNavbarLink,
MDBNavbarNav,
MDBNavbarToggler
} from 'mdb-react-ui-kit';
Properties
CSS variables
As part of MDB’s evolving CSS variables approach, navbar now uses local CSS variables on
.navbar
for enhanced real-time customization. Values for the CSS variables
are set via Sass, so Sass customization is still supported, too.
// Variables for navbar free
// .navbar
--#{$prefix}navbar-padding-x: #{if($navbar-padding-x == null, 0, $navbar-padding-x)};
--#{$prefix}navbar-padding-y: #{$navbar-padding-y};
--#{$prefix}navbar-color: #{$navbar-light-color};
--#{$prefix}navbar-hover-color: #{$navbar-light-hover-color};
--#{$prefix}navbar-disabled-color: #{$navbar-light-disabled-color};
--#{$prefix}navbar-active-color: #{$navbar-light-active-color};
--#{$prefix}navbar-brand-padding-y: #{$navbar-brand-padding-y};
--#{$prefix}navbar-brand-margin-end: #{$navbar-brand-margin-end};
--#{$prefix}navbar-brand-font-size: #{$navbar-brand-font-size};
--#{$prefix}navbar-brand-color: #{$navbar-light-brand-color};
--#{$prefix}navbar-brand-hover-color: #{$navbar-light-brand-hover-color};
--#{$prefix}navbar-nav-link-padding-x: #{$navbar-nav-link-padding-x};
--#{$prefix}navbar-toggler-padding-y: #{$navbar-toggler-padding-y};
--#{$prefix}navbar-toggler-padding-x: #{$navbar-toggler-padding-x};
--#{$prefix}navbar-toggler-font-size: #{$navbar-toggler-font-size};
--#{$prefix}navbar-toggler-icon-bg: #{escape-svg($navbar-light-toggler-icon-bg)};
--#{$prefix}navbar-toggler-border-color: #{$navbar-light-toggler-border-color};
--#{$prefix}navbar-toggler-border-radius: #{$navbar-toggler-border-radius};
--#{$prefix}navbar-toggler-focus-width: #{$navbar-toggler-focus-width};
--#{$prefix}navbar-toggler-transition: #{$navbar-toggler-transition};
--#{$prefix}navbar-box-shadow: #{$navbar-box-shadow};
--#{$prefix}navbar-padding-top: #{$navbar-padding-top};
--#{$prefix}navbar-brand-img-margin-right: #{$navbar-brand-img-margin-right};
// .navbar-nav
--#{$prefix}nav-link-padding-x: 0;
--#{$prefix}nav-link-padding-y: #{$nav-link-padding-y};
@include rfs($nav-link-font-size, --#{$prefix}nav-link-font-size);
--#{$prefix}nav-link-font-weight: #{$nav-link-font-weight};
--#{$prefix}nav-link-color: var(--#{$prefix}navbar-color);
--#{$prefix}nav-link-hover-color: var(--#{$prefix}navbar-hover-color);
--#{$prefix}nav-link-disabled-color: var(--#{$prefix}navbar-disabled-color);
// .navbar-dark
--#{$prefix}navbar-color: #{$navbar-dark-color};
--#{$prefix}navbar-hover-color: #{$navbar-dark-hover-color};
--#{$prefix}navbar-disabled-color: #{$navbar-dark-disabled-color};
--#{$prefix}navbar-active-color: #{$navbar-dark-active-color};
--#{$prefix}navbar-brand-color: #{$navbar-dark-brand-color};
--#{$prefix}navbar-brand-hover-color: #{$navbar-dark-brand-hover-color};
--#{$prefix}navbar-toggler-border-color: #{$navbar-dark-toggler-border-color};
--#{$prefix}navbar-toggler-icon-bg: #{escape-svg($navbar-dark-toggler-icon-bg)};
// Variables for navbar pro
// .navbar
--#{$prefix}navbar-scroll-transition: #{$navbar-scroll-transition};
--#{$prefix}navbar-scroll-scrolled-padding-y: #{$navbar-scroll-scrolled-padding-y};
--#{$prefix}navbar-scroll-scrolled-color: #{$navbar-scroll-scrolled-color};
--#{$prefix}navbar-scroll-color: #{$navbar-scroll-color};
--#{$prefix}navbar-scrolled-bg: #{$navbar-scrolled-bg};
SCSS variables
$navbar-padding-y: $spacer * 0.5;
$navbar-padding-x: null;
$navbar-nav-link-padding-x: 0.5rem;
$navbar-brand-font-size: $font-size-lg;
// Compute the navbar-brand padding-y so the navbar-brand will have the same height as navbar-text and nav-link
$nav-link-height: $font-size-base * $line-height-base + $nav-link-padding-y * 2;
$navbar-brand-height: $navbar-brand-font-size * $line-height-base;
$navbar-brand-padding-y: ($nav-link-height - $navbar-brand-height) * 0.5;
$navbar-brand-margin-end: 1rem;
$navbar-toggler-padding-y: 0.25rem;
$navbar-toggler-padding-x: 0.75rem;
$navbar-toggler-font-size: $font-size-lg;
$navbar-toggler-border-radius: $btn-border-radius;
$navbar-toggler-focus-width: $btn-focus-width;
$navbar-toggler-transition: box-shadow 0.15s ease-in-out;
$navbar-light-color: rgba($black, 0.55);
$navbar-light-hover-color: rgba($black, 0.7);
$navbar-light-active-color: rgba($black, 0.9);
$navbar-light-disabled-color: rgba($black, 0.3);
$navbar-light-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-light-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-light-toggler-border-color: rgba($black, 0.1);
$navbar-light-brand-color: $navbar-light-active-color;
$navbar-light-brand-hover-color: $navbar-light-active-color;
$navbar-dark-color: rgba($white, 0.55);
$navbar-dark-hover-color: rgba($white, 0.75);
$navbar-dark-active-color: $white;
$navbar-dark-disabled-color: rgba($white, 0.25);
$navbar-dark-toggler-icon-bg: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'><path stroke='#{$navbar-dark-color}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/></svg>");
$navbar-dark-toggler-border-color: rgba($white, 0.1);
$navbar-dark-brand-color: $navbar-dark-active-color;
$navbar-dark-brand-hover-color: $navbar-dark-active-color;
$navbar-box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.05);
$navbar-padding-top: 0.5625rem;
$navbar-brand-img-margin-right: 0.25rem;
// Variables for navbar pro
$navbar-scroll-transition: background 0.5s ease-in-out, padding 0.5s ease-in-out;
$navbar-scroll-scrolled-padding-y: 5px;
$navbar-scroll-scrolled-color: #4f4f4f;
$navbar-scroll-color: #fff;
$navbar-scrolled-bg: #fff;