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.

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.

More optionsFewer options

Built with

Two ways to grow to the answer's height; they look alike.

The arrow turns to point up while an answer is open.

The answer's text fades in as its box opens.

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.

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 GitHub

What it is

The full explanation is in README.md.

Good for

  • FAQ pages
  • Settings
  • Menus
  • Long documents

Avoid on

  • Key information
  • Short content