Sidenav
Bootstrap 5 Sidenav component
The side navigation component provides an easy way to navigate through your website. Its appearance & behaviour are easily adjustable with data-mdb-attributes and methods - additional functionality such as touch events and focus trap (in an over mode) are available out of the box.
Note: Read the API tab to find all available options and advanced customization
Video tutorial
*
*
UMD autoinits are enabled
by default. This means that you don't need to initialize
the component manually. However if you are using MDBootstrap ES format then you should pass
the required components to the initMDB
method.
Basic example
In the basic version, the side navigation will appear over your website's content after clicking on a toggler.
Note: Use show
and hide
methods to toggle navigation with
JavaScript.
Note: Adding the show
class to a sidenav collapse element will expand this
category on render.
Inner scroll
Passing a selector of an inner element to the
scrollContainer
option will initialize MDB scrollbar only on this container (by
default it's initialized on the sidenav's main element).
Full-screen examples
The following examples show various settings of the side navigation component in a full-screen mode.
2. Side navigation with a mode transition
Resize the window to change the mode from side
to over
.
3. Slim side navigation (dark)
Non-expandable slim sidenav with a dark background and custom width.
Sidenav small and with categories
Sidenav - API
Import
Importing components depends on how your application works. If you intend to use the MDBootstrap ES
format, you must
first import the component and then initialize it with the initMDB
method. If you are going to use the UMD
format,
just import the mdb-ui-kit
package.
Usage
Via data attributes
Using the Sidenav component doesn't require any additional JavaScript code - simply add
data-mdb-sidenav-init
attribute to
element with .sidenav
class
and use other data attributes to set all options.
For ES
format, you must first import and call the initMDB
method.
Via JavaScript
Via jQuery
Note: By default, MDB does not include jQuery and you have to add it to the project on your own.
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to
data-mdb-
, as in data-mdb-backdrop-class=""
.
Name | Type | Default | Description |
---|---|---|---|
accordion
|
Boolean | false |
Enables accordion behavior in a navigation container |
backdrop
|
Boolean | true |
Adds/removes a backdrop in an over mode |
backdropClass
|
String | null | null |
Adds a custom class to a backdrop |
closeOnEsc
|
Boolean | true |
Closes a side drawer on ESC key (only when toggler is visible) |
color
|
String | 'primary' |
Changes a color of active/hovered links and categories |
content
|
String | null | null |
Selector for a content to which a component will add paddings/margins in push/side modes |
expandOnHover
|
Boolean | false |
Expands/collapses slim mode on mouseover / mouseleave |
focusTrap
|
Boolean | true |
Determines whether focus is trapped within the sidenav on open in over mode |
hidden
|
Boolean | true |
Initializes navigation outside a viewport |
mode |
String | over |
Sets position mode - available options: over , side , push |
scrollContainer
|
String | null | null |
Selector for a scrollable container inside a side drawer |
slim |
Boolean | false |
Enables a slim mode |
slimCollapsed
|
Boolean | false |
Initializes a component in a slim mode |
slimWidth
|
Number | 77 |
A component's width in a slim mode (pixels) |
position
|
String | 'fixed' |
Sets CSS position - accepted values: fixed, absolute |
right |
Boolean | false |
Initializes sidenav on a right side |
transitionDuration
|
Number | 300 |
Sets a length of transitions (in milliseconds) |
width |
Number | 240 |
A component's width (pixels) |
Methods
Name | Description | Example |
---|---|---|
changeMode
|
Changes a position mode (options: over, side, push) |
sidenavInstance.changeMode('push')
|
dispose
|
Removes mdb.Sidenav instance |
sidenavInstance.dispose()
|
getInstance
|
Static method which allows you to get the sidenav instance associated to a DOM element. |
Sidenav.getInstance(sidenav)
|
getOrCreateInstance
|
Static method which returns the sidenav instance associated to a DOM element or create a new one in case it wasn't initialized. |
Sidenav.getOrCreateInstance(sidenav)
|
hide |
Hides a navigation drawer |
sidenavInstance.hide()
|
show |
Shows a navigation drawer |
sidenavInstance.show()
|
toggle |
Manually toggles a component |
sidenavInstance.toggle()
|
toggleSlim
|
Manually toggles a slim state |
sidenavInstance.toggleSlim()
|
update(options)
|
Updates a component |
sidenavInstance.update({ mode: 'side' })
|
Events
Name | Description |
---|---|
show.mdb.sidenav
|
Emitted when a component has been toggled |
shown.mdb.sidenav
|
Emitted once a component is shown (after transition) |
hide.mdb.sidenav
|
Emitted when a component has been toggled |
hidden.mdb.sidenav
|
Emitted once a component is hidden (after transition) |
expand.mdb.sidenav
|
Emitted when a slim mode has been toggled |
expanded.mdb.sidenav
|
Emitted once a component has expanded from a slim mode (after transition) |
collapse.mdb.sidenav
|
Emitted when a slim mode has been toggled |
collapsed.mdb.sidenav
|
Emitted once a component has collapsed into a slim mode (after transition) |
update.mdb.sidenav
|
Emitted whenever a content's offset should be updated (push/side mode). You can access
the suggested values by
event.padding and event.margin properties
|
CSS variables
As part of MDB’s evolving CSS variables approach, sidenav now use local CSS variables on .sidenav
and .sidenav-backdrop
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
Sidenav CSS variables are in different classes which belong to this component. To make it easier to use them, you can find below all of the used CSS variables.