| Class name | Type | Description |
|---|---|---|
collapse |
Component | Collapse |
collapse-title |
Part | Title part |
collapse-content |
Part | Content part |
collapse-arrow |
Modifier | Adds arrow icon |
collapse-plus |
Modifier | Adds plus/minus icon |
collapse-open |
Modifier | Force open |
collapse-close |
Modifier | Force close |
Also see accordion examples
If you want the collapsed content to be searcheable in browser use the Collapse using details and summary tag
This collapse works with focus. When div loses focus, it gets closed
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse bg-base-100 border-base-300 border">
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border-base-300 border',
attributes: {'tabindex': '0'},
);
This collapse works with checkbox instead of focus. It needs to get clicked again to get closed.
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div class="collapse bg-base-100 border border-base-300">
<input type="checkbox" />
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
input(type: InputType.checkbox),
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border border-base-300',
);
An alternative where you can also click outside to close it.
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div class="collapse bg-base-100 border border-base-300">
<input id="collapse-1-toggle" type="checkbox" class="peer" />
<label for="collapse-1-toggle" class="fixed inset-0 hidden peer-checked:block"></label>
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm z-1">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
input(classes: 'peer', type: InputType.checkbox, id: 'collapse-1-toggle'),
label(
const [],
classes: 'fixed inset-0 hidden peer-checked:block',
htmlFor: 'collapse-1-toggle',
),
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm z-1',
),
],
classes: 'bg-base-100 border border-base-300',
);
collapse-open and collapse-close doesn't work with this method. You can add/remove open attribute to the details instead
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<details class="collapse bg-base-100 border-base-300 border">
<summary class="collapse-title font-semibold">How do I create an account?</summary>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</details>
details(
[
summary(
[Component.text('How do I create an account?')],
classes: 'collapse-title font-semibold',
),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'collapse bg-base-100 border-base-300 border',
);
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse">
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
attributes: {'tabindex': '0'},
);
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse collapse-arrow bg-base-100 border-base-300 border">
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border-base-300 border',
modifier: CollapseModifier.arrow,
attributes: {'tabindex': '0'},
);
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse collapse-plus bg-base-100 border-base-300 border">
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border-base-300 border',
modifier: CollapseModifier.plus,
attributes: {'tabindex': '0'},
);
We can move the icon using utility classes like
after:start-5 after:end-auto and we can customize the padding like pe-4 ps-12How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse collapse-arrow bg-base-100 border-base-300 border">
<div class="collapse-title font-semibold after:start-5 after:end-auto pe-4 ps-12">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle(
[Component.text('How do I create an account?')],
classes: 'font-semibold after:start-5 after:end-auto pe-4 ps-12',
),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border-base-300 border',
modifier: CollapseModifier.arrow,
attributes: {'tabindex': '0'},
);
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse collapse-open bg-base-100 border-base-300 border">
<div class="collapse-title font-semibold">I have collapse-open class</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('I have collapse-open class')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border-base-300 border',
modifier: CollapseModifier.open,
attributes: {'tabindex': '0'},
);
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="collapse collapse-close bg-base-100 border-base-300 border">
<div class="collapse-title font-semibold">I have collapse-close class</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('I have collapse-close class')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-base-100 border-base-300 border',
modifier: CollapseModifier.close,
attributes: {'tabindex': '0'},
);
Use Tailwind CSS
group and group-focus utilities to apply style when parent div is focusedHow do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div tabindex="0" class="bg-primary text-primary-content focus:bg-secondary focus:text-secondary-content collapse">
<div class="collapse-title font-semibold">How do I create an account?</div>
<div class="collapse-content text-sm">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
CollapseTitle([Component.text('How do I create an account?')], classes: 'font-semibold'),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'text-sm',
),
],
classes: 'bg-primary text-primary-content focus:bg-secondary focus:text-secondary-content',
attributes: {'tabindex': '0'},
);
Use Tailwind CSS
peer and peer-checked utilities to apply style when sibling checkbox is checked
How do I create an account?
Click the "Sign Up" button in the top right corner and follow the registration process.
<div class="bg-base-100 border-base-300 collapse border">
<input type="checkbox" class="peer" />
<div class="collapse-title bg-primary text-primary-content peer-checked:bg-secondary peer-checked:text-secondary-content">How do I create an account?</div>
<div class="collapse-content bg-primary text-primary-content peer-checked:bg-secondary peer-checked:text-secondary-content">Click the "Sign Up" button in the top right corner and follow the registration process.</div>
</div>
Collapse(
[
input(classes: 'peer', type: InputType.checkbox),
CollapseTitle(
[Component.text('How do I create an account?')],
classes: 'bg-primary text-primary-content peer-checked:bg-secondary peer-checked:text-secondary-content',
),
CollapseContent(
[
Component.text('Click the "Sign Up" button in the top right corner and follow the registration process.'),
],
classes: 'bg-primary text-primary-content peer-checked:bg-secondary peer-checked:text-secondary-content',
),
],
classes: 'bg-base-100 border-base-300 border',
);