Accordions
Accordions are useful when there's a lot of information to show on a page, but you want to keep the layout clean and not overwhelm the user with a lot of information. Users have the ability to choose to see what's important to them. It was recently used in a project where we consolidated multiple standalone marketing websites into a single site (catalog) and no longer could have multiple pages per product. Accordions allowed us to have several pages of information on one page.
I've also used variations of these accordions on FAQ and other pages where there are many repeatable instances of information that users can select what's important to them.
How it works
- The script changes the height of the next sibling element when a DIV with class of "collapsible-header" is clicked on.
- The next sibling element is a DIV with the classes of "collapsible-content" and "collapsible-closed."
- The script toggles "collapsible-closed" off/on and that class has a height of "0" making that DIV visible or not.
- This is the simplest way I've seen accordions done.
Sample
More information is contained here.
Code
The code below is the magic that makes the above sample happen.
More information is contained here.
UX/UI advantages of accordions
- the user can select what information pertains to them.
- lots of information can be easily accessed without overwhelming the user.
- virtually an unlimited number of them can be used on a page.
- doesn't require the user to scroll back up to see the contents of the next accordion.
- accordions can be easily styled for different applications.
- it is also easy to nest accordions inside each other.
UX/UI alternatives to accordions
- Plain text
- easily becomes overwhelming to the user if there's a lot of text.
- Tabs
- UI takes less vertical space.
- can become problematic very quickly on mobile
- when there is a lot of text in a tab.
- when there are more than a few tabs.
- requires the user to scroll back up when finished with a tab.
UX/UI debt
- I prefer to have the micro-interaction of a transition, which works fine when accordions aren't nested, but when they are nested, the calculated height of the DIV doesn't work as the contained accordion will expand in size larger than the height of the containing DIV was calculated.
