Accordion
Vertically stacked content containers
Accordions are a great way of organizing lots of content within a single page by separating the content into collapsable containers. Accordions are made up of a accordion
block and the following elements:
accordion__list
must be a ul tagaccordion__item
must be a li tagaccordion__title
a label for each content containeraccordion__content
contains the content that will be expandable and collapsible
- Accordion item 1Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
- Accordion item 2Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
- Accordion item 3Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
<div class="accordion"> <ul class="accordion__list"> <li class="accordion__item"> <a href="#" class="accordion__title">Accordion item 1</a> <div class="accordion__content"> ... </div> </li> <li class="accordion__item"> <a href="#" class="accordion__title">Accordion item 2</a> <div class="accordion__content"> ... </div> </li> <li class="accordion__item"> <a href="#" class="accordion__title">Accordion item 3</a> <div class="accordion__content"> ... </div> </li> </ul> </div>
Apply the is-active
modifier to the accordion__item
element to toggle the open state for that items content. Combine this with JavaScript to give the accordion controls.
- Accordion item 1Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
- Accordion item 2Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
- Accordion item 3Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
CSS variables
You can customize the accordion elements with the following CSS variables.
.accordion { --border-color: hsl(0deg, 0%, 90%, 1); --border-width: 1px; } /* Accordion item */ .accordion__item { --background-color: var(--color-white); } /* Accordion title */ .accordion__title { --background-color: transparent; --font-color: var(--color-black); --padding: 0.75rem 1rem; --active-background-color: var(--color-primary); --active-font-color: var(--color-primary-text); --hover-background-color: var(--color-light); --hover-font-color: var(--color-light-text); } /* Accordion content */ .accordion__content { --background-color: var(--color-white); --font-color: var(--color-black); --padding: 1rem; }
Sass variables
The default styles can be overridden with the following variables. Set one or more of these variables before you import the framework.
Variable | Type | Default value |
---|---|---|
$accordion-background | color | hsl(0deg, 0%, 100%, 1) |
$accordion-border-width | units | 1px |
$accordion-border-color | color | hsl(0deg, 0%, 90%, 1) |
$accordion-hover-background | color | hsl(0deg, 0%, 96%, 1) |
$accordion-hover-color | color | hsl(0deg, 0%, 22%, 1) |
$accordion-active-background | color | hsl(255, 73%, 58%, 1) |
$accordion-active-color | color | hsl(0deg, 0%, 100%, 1) |
$accordion-title-color | color | hsl(0deg, 0%, 22%, 1) |
$accordion-title-background-color | color | transparent |
$accordion-title-padding | padding | 0.75rem 1rem |
$accordion-content-padding | units | 1rem |
$accordion-content-color | color | hsl(0deg, 0%, 22%, 1) |
$accordion-content-background | color | hsl(0deg, 0%, 100%, 1) |