Hamburger Menu
React Bootstrap 5 Hamburger Menu
Responsive React Hamburger button menu with Bootstrap 5. Hamburger toggle menu for mobile navigation, icon animations, sidenav, navbar templates & more.
Hamburger menu is a navigation type that serves the purpose of hiding some menu items & showing them on click. It stacks the items on top of each other in a "hamburger" fashion.
Basic example
Simple example of a hamburger menu in a navbar.
import React, { useState } from 'react';
import {
MDBContainer,
MDBCollapse,
MDBNavbar,
MDBNavbarToggler,
MDBIcon,
MDBBtn,
} from 'mdb-react-ui-kit';
export default function App() {
const [showNavExternal, setShowNavExternal] = useState(false);
return (
<>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowNavExternal(!showNavExternal)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showNavExternal}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</>
);
}
Hamburger Icons
Examples of icon usage in Bootstrap Hamburger menu.
You will find even more icons in the Icons Documentation.
Custom icons
You can make any icon a hamburger menu toggler.
import React, { useState } from 'react';
import {
MDBContainer,
MDBCollapse,
MDBNavbar,
MDBNavbarToggler,
MDBIcon,
MDBBtn,
} from 'mdb-react-ui-kit';
export default function App() {
const [showCustomIcons, setShowCustomIcons] = useState(false);
const [showCustomIcons2, setShowCustomIcons2] = useState(false);
const [showCustomIcons3, setShowCustomIcons3] = useState(false);
const [showCustomIcons4, setShowCustomIcons4] = useState(false);
const [showCustomIcons5, setShowCustomIcons5] = useState(false);
return (
<>
<section className='mb-3'>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowCustomIcons(!showCustomIcons)}
>
<MDBIcon icon='bars' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showCustomIcons}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
<section className='mb-3'>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowCustomIcons2(!showCustomIcons2)}
>
<MDBIcon icon='hamburger' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showCustomIcons2}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
<section className='mb-3'>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowCustomIcons3(!showCustomIcons3)}
>
<MDBIcon icon='chevron-circle-down' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showCustomIcons3}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
<section className='mb-3'>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowCustomIcons4(!showCustomIcons4)}
>
<MDBIcon icon='ellipsis-h' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showCustomIcons4}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
<section className='mb-3'>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowCustomIcons5(!showCustomIcons5)}
>
<MDBIcon icon='compass' fas />
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showCustomIcons5}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
</>
);
}
Animated icons
Animated hamburger menu icons add dynamism to your design.
import React, { useState } from 'react';
import {
MDBContainer,
MDBCollapse,
MDBNavbar,
MDBNavbarToggler,
MDBIcon,
MDBBtn,
} from 'mdb-react-ui-kit';
export default function App() {
const [showAnimated, setShowAnimated] = useState(false);
const [showAnimated2, setShowAnimated2] = useState(false);
const [showAnimated3, setShowAnimated3] = useState(false);
return (
<>
<section className='mb-3'>
<MDBNavbar>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
className='first-button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowAnimated(!showAnimated)}
>
<div className={`animated-icon1 ${showAnimated && 'open'}`}>
<span></span>
<span></span>
<span></span>
</div>
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showAnimated}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
<section className='mb-3'>
<MDBNavbar dark bgColor='dark'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
className='second-button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowAnimated2(!showAnimated2)}
>
<div className={`animated-icon2 ${showAnimated2 && 'open'}`}>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showAnimated2}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
<section className='mb-3'>
<MDBNavbar dark bgColor='info'>
<MDBContainer fluid>
<MDBNavbarToggler
type='button'
className='third-button'
data-target='#navbarToggleExternalContent'
aria-controls='navbarToggleExternalContent'
aria-expanded='false'
aria-label='Toggle navigation'
onClick={() => setShowAnimated3(!showAnimated3)}
>
<div className={`animated-icon3 ${showAnimated3 && 'open'}`}>
<span></span>
<span></span>
<span></span>
</div>
</MDBNavbarToggler>
</MDBContainer>
</MDBNavbar>
<MDBCollapse show={showAnimated3}>
<div className='bg-light shadow-3 p-4'>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 1
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
<MDBBtn block className='border-bottom m-0' color='link'>
Link 2
</MDBBtn>
</div>
</MDBCollapse>
</section>
</>
);
}
/* Icon 1 */
.animated-icon1,
.animated-icon2,
.animated-icon3 {
width: 30px;
height: 20px;
position: relative;
margin: 0px;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
cursor: pointer;
}
.animated-icon1 span,
.animated-icon2 span,
.animated-icon3 span {
display: block;
position: absolute;
height: 3px;
width: 100%;
border-radius: 9px;
opacity: 1;
left: 0;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: .25s ease-in-out;
-moz-transition: .25s ease-in-out;
-o-transition: .25s ease-in-out;
transition: .25s ease-in-out;
}
.animated-icon1 span {
background: #2d7ef7;
}
.animated-icon2 span {
background: #e3f2fd;
}
.animated-icon3 span {
background: #f3e5f5;
}
.animated-icon1 span:nth-child(1) {
top: 0px;
}
.animated-icon1 span:nth-child(2) {
top: 10px;
}
.animated-icon1 span:nth-child(3) {
top: 20px;
}
.animated-icon1.open span:nth-child(1) {
top: 11px;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
}
.animated-icon1.open span:nth-child(2) {
opacity: 0;
left: -60px;
}
.animated-icon1.open span:nth-child(3) {
top: 11px;
-webkit-transform: rotate(-135deg);
-moz-transform: rotate(-135deg);
-o-transform: rotate(-135deg);
transform: rotate(-135deg);
}
/* Icon 3*/
.animated-icon2 span:nth-child(1) {
top: 0px;
}
.animated-icon2 span:nth-child(2),
.animated-icon2 span:nth-child(3) {
top: 10px;
}
.animated-icon2 span:nth-child(4) {
top: 20px;
}
.animated-icon2.open span:nth-child(1) {
top: 11px;
width: 0%;
left: 50%;
}
.animated-icon2.open span:nth-child(2) {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
.animated-icon2.open span:nth-child(3) {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.animated-icon2.open span:nth-child(4) {
top: 11px;
width: 0%;
left: 50%;
}
/* Icon 4 */
.animated-icon3 span:nth-child(1) {
top: 0px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
.animated-icon3 span:nth-child(2) {
top: 10px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
.animated-icon3 span:nth-child(3) {
top: 20px;
-webkit-transform-origin: left center;
-moz-transform-origin: left center;
-o-transform-origin: left center;
transform-origin: left center;
}
.animated-icon3.open span:nth-child(1) {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
top: 0px;
left: 8px;
}
.animated-icon3.open span:nth-child(2) {
width: 0%;
opacity: 0;
}
.animated-icon3.open span:nth-child(3) {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
top: 21px;
left: 8px;
}