Basic example
The collapse od used in the accordion component to make it fold and unfold.
<a
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
data-twe-collapse-init
data-twe-ripple-init
data-twe-ripple-color="light"
href="#collapseExample"
role="button"
aria-expanded="false"
aria-controls="collapseExample">
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-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
type="button"
data-twe-collapse-init
data-twe-ripple-init
data-twe-ripple-color="light"
data-twe-target="#collapseExample"
aria-expanded="false"
aria-controls="collapseExample">
Button with data-twe-target
</button>
<div
class="!visible hidden text-center"
id="collapseExample"
data-twe-collapse-item>
Some placeholder content for the collapse component. This panel is
hidden by default but revealed when the user activates the relevant
trigger.
</div>
// Initialization for ES Users
import {
Collapse,
Ripple,
initTWE,
} from "tw-elements";
initTWE({ Collapse, Ripple });
Horizontal
Use the [data-twe-collapse-horizontal]
attribute to transition
the width instead of height and set a width on the immediate child element.
<button
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
type="button"
data-twe-collapse-init
data-twe-target="#collapseWidthExample"
data-twe-ripple-init
data-twe-ripple-color="light"
aria-expanded="false"
aria-controls="collapseWidthExample">
Toggle width collapse
</button>
<div
class="!visible hidden"
data-twe-collapse-item
data-twe-collapse-horizontal
id="collapseWidthExample">
<div>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
// Initialization for ES Users
import {
Collapse,
Ripple,
initTWE,
} from "tw-elements";
initTWE({ Collapse, Ripple });
Multiple targets
Hide multiple elements by referencing them with a selector in its
href
or data-twe-target
attribute. Multiple
button
or a
can show and hide an element if they
each reference it with their href or data-twe-target attribute.
<a
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
data-twe-collapse-init
data-twe-ripple-init
data-twe-ripple-color="light"
href="#multiCollapseExample1"
role="button"
aria-expanded="false"
aria-controls="multiCollapseExample1"
>Toggle first element</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-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
type="button"
data-twe-collapse-init
data-twe-target="#multiCollapseExample2"
data-twe-ripple-init
data-twe-ripple-color="light"
aria-expanded="false"
aria-controls="multiCollapseExample2">
Toggle second element
</button>
<button
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
type="button"
data-twe-collapse-init
data-twe-target=".multi-collapse"
data-twe-ripple-init
data-twe-ripple-color="light"
aria-expanded="false"
aria-controls="multiCollapseExample1 multiCollapseExample2">
Toggle both elements
</button>
<div class="mt-4 grid gap-4 md:grid-cols-2">
<div>
<div
class="multi-collapse !visible hidden"
data-twe-collapse-item
id="multiCollapseExample1">
<div>
Some placeholder content for the first collapse component of this
multi-collapse example. This panel is hidden by default but
revealed when the user activates the relevant trigger.
</div>
</div>
</div>
<div>
<div
class="multi-collapse !visible hidden"
data-twe-collapse-item
id="multiCollapseExample2">
<div>
Some placeholder content for the second collapse component of this
multi-collapse example. This panel is hidden by default but
revealed when the user activates the relevant trigger.
</div>
</div>
</div>
</div>
// Initialization for ES Users
import {
Collapse,
Ripple,
initTWE,
} from "tw-elements";
initTWE({ Collapse, Ripple });
With Scroll
Use custom styles with specified height to see content with scrollbar.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et.
<a
class="mx-auto inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium uppercase leading-normal text-white shadow-primary-3 transition duration-150 ease-in-out hover:bg-primary-accent-300 hover:shadow-primary-2 focus:bg-primary-accent-300 focus:shadow-primary-2 focus:outline-none focus:ring-0 active:bg-primary-600 active:shadow-primary-2 dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
data-twe-collapse-init
data-twe-ripple-init
data-twe-ripple-color="light"
href="#collapseWithScrollbar"
role="button"
aria-expanded="false"
aria-controls="collapseWithScrollbar">
Longer content
</a>
<div
class="!visible mx-auto mt-4 hidden max-h-24 overflow-y-auto"
data-twe-collapse-item
id="collapseWithScrollbar"
style="max-width: 500px">
<p>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident. Ad vegan
excepteur butcher vice lomo. Leggings occaecat craft beer
farm-to-table, raw denim aesthetic synth nesciunt you probably haven't
heard of them accusamus labore sustainable VHS. 3 wolf moon officia
aute, non cupidatat skateboard dolor brunch. Food truck quinoa
nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a
bird on it squid single-origin coffee nulla assumenda shoreditch et.
</p>
</div>
// Initialization for ES Users
import {
Collapse,
Ripple,
initTWE,
} from "tw-elements";
initTWE({ Collapse, Ripple });