Basic
Offcanvas is a sidebar component that can be toggled to appear from the left, right, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle.
Use bottom-0
, top-0
and
left-0
classes to place offcanvas on the left of the viewport.
Offcanvas
<div class="flex space-x-2">
<div>
<a
class="mr-1.5 inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)]"
data-te-offcanvas-toggle
href="#offcanvasExample"
role="button"
aria-controls="offcanvasExample"
data-te-ripple-init
data-te-ripple-color="light">
Link with href
</a>
<button
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)]"
type="button"
data-te-offcanvas-toggle
data-te-target="#offcanvasExample"
aria-controls="offcanvasExample"
data-te-ripple-init
data-te-ripple-color="light">
Button with data-te-target
</button>
<div
class="invisible fixed bottom-0 left-0 top-0 z-[1045] flex w-96 max-w-full -translate-x-full flex-col border-none bg-white bg-clip-padding text-neutral-700 shadow-sm outline-none transition duration-300 ease-in-out dark:bg-neutral-800 dark:text-neutral-200 [&[data-te-offcanvas-show]]:transform-none"
tabindex="-1"
id="offcanvasExample"
aria-labelledby="offcanvasExampleLabel"
data-te-offcanvas-init>
<div class="flex items-center justify-between p-4">
<h5
class="mb-0 font-semibold leading-normal"
id="offcanvasExampleLabel">
Offcanvas
</h5>
<button
type="button"
class="box-content rounded-none border-none opacity-50 hover:no-underline hover:opacity-75 focus:opacity-100 focus:shadow-none focus:outline-none"
data-te-offcanvas-dismiss>
<span
class="w-[1em] focus:opacity-100 disabled:pointer-events-none disabled:select-none disabled:opacity-25 [&.disabled]:pointer-events-none [&.disabled]:select-none [&.disabled]:opacity-25">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12" />
</svg>
</span>
</button>
</div>
<div class="flex-grow overflow-y-auto p-4">
<div>
Some text as placeholder. In real life you can have the elements
you have chosen. Like, text, images, lists, etc.
</div>
<div class="relative mt-4" data-te-dropdown-ref>
<button
class="flex items-center whitespace-nowrap rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] motion-reduce:transition-none"
type="button"
id="dropdownMenuButton"
data-te-dropdown-toggle-ref
data-te-ripple-init
data-te-ripple-color="light">
Dropdown button
<span class="ml-2 w-2">
<svg
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="caret-down"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 320 512">
<path
fill="currentColor"
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"></path>
</svg>
</span>
</button>
<ul
class="absolute z-[1000] float-left m-0 hidden min-w-max list-none rounded-lg border-none bg-white bg-clip-padding py-2 text-left text-base shadow-lg dark:bg-neutral-700 dark:text-neutral-200 [&[data-te-dropdown-show]]:block"
aria-labelledby="dropdownMenuButton"
data-te-dropdown-menu-ref>
<li>
<a
class="block w-full whitespace-nowrap bg-transparent px-4 py-2 text-sm font-normal text-neutral-700 hover:bg-neutral-100 active:text-neutral-800 active:no-underline disabled:pointer-events-none disabled:bg-transparent disabled:text-neutral-400 dark:text-neutral-100 dark:hover:bg-neutral-500 dark:focus:bg-neutral-500"
href="#"
data-te-dropdown-item-ref
>Action
</a>
</li>
<li>
<a
class="block w-full whitespace-nowrap bg-transparent px-4 py-2 text-sm font-normal text-neutral-700 hover:bg-neutral-100 active:text-neutral-800 active:no-underline disabled:pointer-events-none disabled:bg-transparent disabled:text-neutral-400 dark:text-neutral-100 dark:hover:bg-neutral-500 dark:focus:bg-neutral-500"
href="#"
data-te-dropdown-item-ref
>Another action
</a>
</li>
<li>
<a
class="block w-full whitespace-nowrap bg-transparent px-4 py-2 text-sm font-normal text-neutral-700 hover:bg-neutral-100 active:text-neutral-800 active:no-underline disabled:pointer-events-none disabled:bg-transparent disabled:text-neutral-400 dark:text-neutral-100 dark:hover:bg-neutral-500 dark:focus:bg-neutral-500"
href="#"
data-te-dropdown-item-ref
>Something else here
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
// Initialization for ES Users
import {
Offcanvas,
Ripple,
Dropdown,
initTE,
} from "tw-elements";
initTE({ Offcanvas, Ripple, Dropdown });
Hey there 👋 we want to make TW elements a community-driven project. It's open source and free, and we would like it to stay that way. If you enjoy it, help the project grow by sharing it with your peers. Every share counts, thank you!
Placement - top
Use top-0
, left-0
and right-0
classes
to place offcanvas on the top of the viewport.
Offcanvas top
<button
class="mr-1.5 inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)]"
type="button"
data-te-offcanvas-toggle
data-te-target="#offcanvasTop"
aria-controls="offcanvasTop"
data-te-ripple-init
data-te-ripple-color="light">
Toggle top offcanvas
</button>
<div
class="invisible fixed bottom-0 left-0 right-0 top-0 z-[1045] flex h-1/3 max-h-full max-w-full -translate-y-full flex-col border-none bg-white bg-clip-padding text-neutral-700 shadow-sm outline-none transition duration-300 ease-in-out dark:bg-neutral-800 dark:text-neutral-200 [&[data-te-offcanvas-show]]:transform-none"
tabindex="-1"
id="offcanvasTop"
aria-labelledby="offcanvasTopLabel"
data-te-offcanvas-init>
<div class="flex items-center justify-between p-4">
<h5 class="mb-0 font-semibold leading-normal" id="offcanvasTopLabel">
Offcanvas top
</h5>
<button
type="button"
class="box-content rounded-none border-none opacity-50 hover:no-underline hover:opacity-75 focus:opacity-100 focus:shadow-none focus:outline-none"
data-te-offcanvas-dismiss>
<span
class="w-[1em] focus:opacity-100 disabled:pointer-events-none disabled:select-none disabled:opacity-25 [&.disabled]:pointer-events-none [&.disabled]:select-none [&.disabled]:opacity-25">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12" />
</svg>
</span>
</button>
</div>
<div class="flex-grow overflow-y-auto p-4">...</div>
</div>
// Initialization for ES Users
import {
Offcanvas,
Ripple,
initTE,
} from "tw-elements";
initTE({ Offcanvas, Ripple });
Placement - right
Use top-0
, right-0
, w-96
classes to
place offcanvas on the right of the viewport.
Offcanvas right
<button
class="mr-1.5 inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)]"
type="button"
data-te-offcanvas-toggle
data-te-target="#offcanvasRight"
aria-controls="offcanvasRight"
data-te-ripple-init
data-te-ripple-color="light">
Toggle right offcanvas
</button>
<div
class="invisible fixed bottom-0 right-0 top-0 z-[1045] flex w-96 max-w-full translate-x-full flex-col border-none bg-white bg-clip-padding text-neutral-700 shadow-sm outline-none transition duration-300 ease-in-out dark:bg-neutral-800 dark:text-neutral-200 [&[data-te-offcanvas-show]]:transform-none"
tabindex="-1"
id="offcanvasRight"
aria-labelledby="offcanvasRightLabel"
data-te-offcanvas-init>
<div class="flex items-center justify-between p-4">
<h5
class="mb-0 font-semibold leading-normal"
id="offcanvasRightLabel">
Offcanvas right
</h5>
<button
type="button"
class="box-content rounded-none border-none opacity-50 hover:no-underline hover:opacity-75 focus:opacity-100 focus:shadow-none focus:outline-none"
data-te-offcanvas-dismiss>
<span
class="w-[1em] focus:opacity-100 disabled:pointer-events-none disabled:select-none disabled:opacity-25 [&.disabled]:pointer-events-none [&.disabled]:select-none [&.disabled]:opacity-25">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12" />
</svg>
</span>
</button>
</div>
<div class="offcanvas-body flex-grow overflow-y-auto p-4">...</div>
</div>
// Initialization for ES Users
import {
Offcanvas,
Ripple,
initTE,
} from "tw-elements";
initTE({ Offcanvas, Ripple });
Placement - bottom
Use bottom-0
, left-0
, right-0
classes
to place offcanvas on the bottom of the viewport.
Offcanvas bottom
<button
class="mr-1.5 inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)]"
type="button"
data-te-offcanvas-toggle
data-te-target="#offcanvasBottom"
aria-controls="offcanvasBottom"
data-te-ripple-init
data-te-ripple-color="light">
Toggle bottom offcanvas
</button>
<div
class="invisible fixed bottom-0 left-0 right-0 z-[1045] flex h-1/3 max-h-full max-w-full translate-y-full flex-col border-none bg-white bg-clip-padding text-neutral-700 shadow-sm outline-none transition duration-300 ease-in-out dark:bg-neutral-800 dark:text-neutral-200 [&[data-te-offcanvas-show]]:transform-none"
tabindex="-1"
id="offcanvasBottom"
aria-labelledby="offcanvasBottomLabel"
data-te-offcanvas-init>
<div class="flex items-center justify-between p-4">
<h5
class="mb-0 font-semibold leading-normal"
id="offcanvasBottomLabel">
Offcanvas bottom
</h5>
<button
type="button"
class="box-content rounded-none border-none opacity-50 hover:no-underline hover:opacity-75 focus:opacity-100 focus:shadow-none focus:outline-none"
data-te-offcanvas-dismiss>
<span
class="w-[1em] focus:opacity-100 disabled:pointer-events-none disabled:select-none disabled:opacity-25 [&.disabled]:pointer-events-none [&.disabled]:select-none [&.disabled]:opacity-25">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="h-6 w-6">
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M6 18L18 6M6 6l12 12" />
</svg>
</span>
</button>
</div>
<div class="small flex-grow overflow-y-auto p-4">...</div>
</div>
// Initialization for ES Users
import {
Offcanvas,
Ripple,
initTE,
} from "tw-elements";
initTE({ Offcanvas, Ripple });