Skip to content

Accordion

Example Usage

Summary Accordion

This accordion has a basic open close mechanic from the details/summary tag used.

Trigger 1

Lorem ipsum dolor sit amet. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit, non?

Lorem ipsum dolor sit amet. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit, non?

Named Summary Accordion

Building on the initial Summary accordion, the use of the name attribute on the details tag allows only one section to be open at a time.

Trigger 1

Lorem ipsum dolor sit amet. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit, non?

Lorem ipsum dolor sit amet. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Lorem ipsum dolor sit amet consectetur adipisicing elit. Reprehenderit, non?

CSS Variables

The accordion system can be customized using CSS variables:

Layout and Sizing

VariableDefault ValueDescription
--accordion-gap0emHorizontal space between sections
--accordion-wrapper-padding0pxHorizontal padding between the border of the accordion and its content

Trigger Configuration

VariableDefault ValueDescription
--accordion-inner-margin0pxShared value between trigger and content to align text
--accordion-inner-padding1em 1.5emShared value between trigger and content to align text

Icon Configuration

VariableDefault ValueDescription
--accordion-icon-expanded-transformrotate(180deg)Transformation to apply when panel is expanded
--accordion-icon-transitionall var(--duration-speed-quick) ease-inTransition to apply for icon animations
--accordion-icon-collapsed-transformrotate(0deg)Transformation to apply when panel is collapsed

Borders and Styling

VariableDefault ValueDescription
--accordion-radiusnoneRounding on outer borders
--accordion-section-radiusnoneRounding on section borders
--accordion-bordernoneBorder thickness around the accordion
--accordion-divider-width2pxWidth of divider lines between accordion sections
--accordion-closed-divider-lightness20%Lightness of dividers between closed accordion sections, as a percentage of the skins border colour blended with its background colour

Accessibility

Using the pattern of the html details and summary tags allows the open/close interactivity of the accordion. To make it WCAG compliant and to activate some css based on aria changes, some Javascript will need to be implemented in the final version.

Current Implementation Features

Structure and Labeling

Each trigger has a role of button to indicate it’s interactivity to screen readers. Every accordion section has aria to link the trigger / heading of the section to its content

Keyboard Support

The current implementation provides:

Tab navigation between focusable elements Focus indicators on interactive elements Space/Enter keys to open/close the dropdown

Screen Reader Support

ARIA State Management

Update the following ARIA states dynamically:

  • aria-expanded This should be toggled with javascript
  • aria-controls=ID link the top level element around the trigger for an accordion panel
  • Use role=region / aria-labelledby on the accordion content panel div, to demonstrate the link to the button controlling visibility

This is not a typical implementation of aria and accessibility. It is known to work against Android talkback and Apple VoiceOver screen-readers. If a fully WCAG compliant version is needed, please refer to the WCAGAccordion example. This will need Javascript implementation to make it interactive.

Keyboard Navigation

These are met by default, but after any Javascript additions to the accordion, it should be confirmed that they are still met:

  • Tab moves focus to the next focusable element
  • Shift / Tab moves focus to the previous focusable element
  • Enter / Space expands a collapsed tab