Drawer is a grid layout that can show/hide a sidebar on the left or right side of the page.
Class name | Type | |
---|---|---|
drawer | Component | The wrapper for sidebar and content |
drawer-toggle | Part | The hidden checkbox that controls the state of drawer |
drawer-content | Part | Content part |
drawer-side | Part | Sidebar part |
drawer-overlay | Part | Label that covers the page when drawer is open |
drawer-end | Placement | puts drawer to the other side |
drawer-open | Modifier | Forces the drawer to be open |
.drawer // The root container
├── .drawer-toggle // A hidden checkbox to toggle the visibility of the sidebar
├── .drawer-content // All your page content goes here
│ ├── // navbar
│ ├── // content
│ ╰── // footer
╰── .drawer-side // Sidebar wrapper
├── .drawer-overlay // A dark overlay that covers the whole page when the drawer is open
╰── // Sidebar content (menu or anything)
Drawer sidebar is hidden by default. You can make it visible on larger screens using
lg:drawer-open
class (or using other responsive prefixes: sm, md, lg, xl)
You can check/uncheck the checkbox using JavaScript or by clicking the
label
tag which is assigned to the hidden checkbox
<div class="$$drawer"> <input id="my-drawer" type="checkbox" class="$$drawer-toggle" /> <div class="$$drawer-content"> <!-- Page content here --> <label for="my-drawer" class="$$btn $$btn-primary $$drawer-button">Open drawer</label> </div> <div class="$$drawer-side"> <label for="my-drawer" aria-label="close sidebar" class="$$drawer-overlay"></label> <ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4"> <!-- Sidebar content here --> <li><a>Sidebar Item 1</a></li> <li><a>Sidebar Item 2</a></li> </ul> </div> </div>
<div class="$$drawer">
<input id="my-drawer" type="checkbox" class="$$drawer-toggle" />
<div class="$$drawer-content">
<!-- Page content here -->
<label for="my-drawer" class="$$btn $$btn-primary $$drawer-button">Open drawer</label>
</div>
<div class="$$drawer-side">
<label for="my-drawer" aria-label="close sidebar" class="$$drawer-overlay"></label>
<ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>
<div class="$$drawer"> <input id="my-drawer" type="checkbox" class="$$drawer-toggle" /> <div class="$$drawer-content"> <!-- Page content here --> <label for="my-drawer" class="$$btn $$btn-primary $$drawer-button">Open drawer</label> </div> <div class="$$drawer-side"> <label for="my-drawer" aria-label="close sidebar" class="$$drawer-overlay"></label> <ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4"> <!-- Sidebar content here --> <li><a>Sidebar Item 1</a></li> <li><a>Sidebar Item 2</a></li> </ul> </div> </div>
<div class="$$drawer">
<input id="my-drawer" type="checkbox" class="$$drawer-toggle" />
<div class="$$drawer-content">
<!-- Page content here -->
<label for="my-drawer" class="$$btn $$btn-primary $$drawer-button">Open drawer</label>
</div>
<div class="$$drawer-side">
<label for="my-drawer" aria-label="close sidebar" class="$$drawer-overlay"></label>
<ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>
<div class="$$drawer lg:$$drawer-open"> <input id="my-drawer-2" type="checkbox" class="$$drawer-toggle" /> <div class="$$drawer-content flex flex-col items-center justify-center"> <!-- Page content here --> <label for="my-drawer-2" class="$$btn $$btn-primary $$drawer-button lg:hidden"> Open drawer </label> </div> <div class="$$drawer-side"> <label for="my-drawer-2" aria-label="close sidebar" class="$$drawer-overlay"></label> <ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4"> <!-- Sidebar content here --> <li><a>Sidebar Item 1</a></li> <li><a>Sidebar Item 2</a></li> </ul> </div> </div>
<div class="$$drawer lg:$$drawer-open">
<input id="my-drawer-2" type="checkbox" class="$$drawer-toggle" />
<div class="$$drawer-content flex flex-col items-center justify-center">
<!-- Page content here -->
<label for="my-drawer-2" class="$$btn $$btn-primary $$drawer-button lg:hidden">
Open drawer
</label>
</div>
<div class="$$drawer-side">
<label for="my-drawer-2" aria-label="close sidebar" class="$$drawer-overlay"></label>
<ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>
<div class="$$drawer lg:$$drawer-open"> <input id="my-drawer-2" type="checkbox" class="$$drawer-toggle" /> <div class="$$drawer-content flex flex-col items-center justify-center"> <!-- Page content here --> <label for="my-drawer-2" class="$$btn $$btn-primary $$drawer-button lg:hidden"> Open drawer </label> </div> <div class="$$drawer-side"> <label for="my-drawer-2" aria-label="close sidebar" class="$$drawer-overlay"></label> <ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4"> <!-- Sidebar content here --> <li><a>Sidebar Item 1</a></li> <li><a>Sidebar Item 2</a></li> </ul> </div> </div>
<div class="$$drawer lg:$$drawer-open">
<input id="my-drawer-2" type="checkbox" class="$$drawer-toggle" />
<div class="$$drawer-content flex flex-col items-center justify-center">
<!-- Page content here -->
<label for="my-drawer-2" class="$$btn $$btn-primary $$drawer-button lg:hidden">
Open drawer
</label>
</div>
<div class="$$drawer-side">
<label for="my-drawer-2" aria-label="close sidebar" class="$$drawer-overlay"></label>
<ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>
<div class="$$drawer $$drawer-end"> <input id="my-drawer-4" type="checkbox" class="$$drawer-toggle" /> <div class="$$drawer-content"> <!-- Page content here --> <label for="my-drawer-4" class="$$drawer-button $$btn $$btn-primary">Open drawer</label> </div> <div class="$$drawer-side"> <label for="my-drawer-4" aria-label="close sidebar" class="$$drawer-overlay"></label> <ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4"> <!-- Sidebar content here --> <li><a>Sidebar Item 1</a></li> <li><a>Sidebar Item 2</a></li> </ul> </div> </div>
<div class="$$drawer $$drawer-end">
<input id="my-drawer-4" type="checkbox" class="$$drawer-toggle" />
<div class="$$drawer-content">
<!-- Page content here -->
<label for="my-drawer-4" class="$$drawer-button $$btn $$btn-primary">Open drawer</label>
</div>
<div class="$$drawer-side">
<label for="my-drawer-4" aria-label="close sidebar" class="$$drawer-overlay"></label>
<ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>
<div class="$$drawer $$drawer-end"> <input id="my-drawer-4" type="checkbox" class="$$drawer-toggle" /> <div class="$$drawer-content"> <!-- Page content here --> <label for="my-drawer-4" class="$$drawer-button $$btn $$btn-primary">Open drawer</label> </div> <div class="$$drawer-side"> <label for="my-drawer-4" aria-label="close sidebar" class="$$drawer-overlay"></label> <ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4"> <!-- Sidebar content here --> <li><a>Sidebar Item 1</a></li> <li><a>Sidebar Item 2</a></li> </ul> </div> </div>
<div class="$$drawer $$drawer-end">
<input id="my-drawer-4" type="checkbox" class="$$drawer-toggle" />
<div class="$$drawer-content">
<!-- Page content here -->
<label for="my-drawer-4" class="$$drawer-button $$btn $$btn-primary">Open drawer</label>
</div>
<div class="$$drawer-side">
<label for="my-drawer-4" aria-label="close sidebar" class="$$drawer-overlay"></label>
<ul class="$$menu bg-base-200 text-base-content min-h-full w-80 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>