04.19 · Micro-Interactions
Accordion Open/Close
Each question opens smoothly to show its answer. Best for FAQ pages.
Click it
Press a question to open its answer and again to close it, or press Show me.
A stack of headings that each open to show more below them. It keeps a long page short and easy to scan.
When an answer grows into place, the questions below slide down smoothly instead of jumping, so you keep your place.
It depends on the page. Often opening one closes the others, which keeps the list short, while settings pages usually let several stay open.
For questions, settings or long sections that people read one at a time. If everything must be seen at once, show it all instead.
Avoid putting accordions inside accordions; two levels is the most people can follow.
Yes. Each question is a button, so Tab reaches it and Enter or Space opens it, and screen readers hear whether it is open.
Inside, the bracket is the answer's full height, found before it opens; its box grows to meet it and pushes the questions below down. Press a question, or Show me.
Snaps open: the answer appears at once and the questions below jump; Grows open: its box grows and the questions below slide down, so you keep your place. Press a question, or Show me.
Try it
Change a setting, then try it again or press Show me.
Speed
How long an answer takes to open or close.
Feel
Gentle eases in and out; Smooth slows at the end.
Off closes the open answer when you open another.
Copy the prompt
Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.
Add an accordion to [the questions or sections you want to fold away]. Show only the headings at first; when one is pressed, its content box grows from nothing to its full height and the headings below slide down, and pressing it again shrinks it back. Animate the box to the content's real height, never to a large fixed maximum, or the timing looks wrong. When the settings include it, turn a small arrow to show which items are open. Make each heading a real button that tells screen readers whether it is open. If the visitor has reduced motion turned on, open and close the sections without animating. Match the settings listed below.
Your settings
Replace the words in brackets with your own element. Your settings are added at the end.
Free and open source. If this helped, a star on GitHub helps other people find it.
Star on GitHubWhat it is
The full explanation is in README.md.