YouTip LogoYouTip

Bootstrap5 Offcanvas

Bootstrap5 Offcanvas Sidebar Navigation

Bootstrap5 offcanvas sidebars are similar to modals and are commonly used on mobile devices.

Creating Sliding Navigation

We can control the display and hiding of the sidebar by using JavaScript to add or remove the .show class after the .offcanvas class:

  • .offcanvas Hides content (default)
  • .offcanvas.show Shows content

You can set up the sidebar using the href attribute of an <a> link or the data-bs-target attribute of a <button> element. Both cases require data-bs-toggle="offcanvas".

Here is an example of creating sliding navigation:

Example

Using link's href attribute
Sidebar
Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.

Try it Β»


Sidebar Direction

The direction of the sidebar can be controlled using the following four classes:

  • .offcanvas-start Displays on the left, as in the example above.
  • .offcanvas-end Displays on the right
  • .offcanvas-top Displays at the top
  • .offcanvas-bottom Displays at the bottom

Example

Displays in Top Navbar
...

Try it Β»

Example

Displays in Right Sidebar
...

Try it Β»

Example

Displays in Bottom Navbar
...

Try it Β»


Setting Background and Scrollability

We can set whether the <body> element is scrollable when the sidebar is open, and whether to display a backdrop. Use the data-bs-scroll attribute to set if the <body> is scrollable, and data-bs-backdrop to toggle the backdrop display.

Example

Body content is scrollable

Scroll the page to see the effect.

Using backdrop

Body content is not scrollable

Using backdrop, body content is scrollable

Scroll the page to see the effect.

Try it Β»


Sidebar Examples

← Docker Start Stop Restart CommBootstrap5 Popover β†’