# Accordion

Printed sections that open in place. Each head ends in a small square key printed +; open, the key latches below the plate and reads −.

Kit part · Free · https://tactileui.dev/parts/accordion

- Element: `<details>`
- Needs: `kit.css` only, no script ([how to install the kit](https://tactileui.dev/docs/installation#the-kit))
- Categories: Accordions
- Finishes: Aluminium, Graphite, Oak, Walnut, Porcelain, Black, Daylight, Night, Paper, Phosphor, E-paper, AMOLED
- Volumes: Tactile, Quiet

## Variants

### One open at a time · shared name

```html
<div class="tui-accordion" style="width:220px"><details class="tui-accordion__item" name="acc-v1" open><summary>Tariff</summary><div class="tui-accordion__body"><p>Flux, three rates a day.</p></div></details><details class="tui-accordion__item" name="acc-v1"><summary>Reserve</summary><div class="tui-accordion__body"><p>Kept for a power cut: 20%.</p></div></details></div>
```

### Several open · no name

```html
<div class="tui-accordion" style="width:220px"><details class="tui-accordion__item" open><summary>Circuits</summary><div class="tui-accordion__body"><p>Twelve on the board.</p></div></details><details class="tui-accordion__item" open><summary>Meters</summary><div class="tui-accordion__body"><p>One import, one export.</p></div></details></div>
```

### Numbered, with a figure

```html
<div class="tui-accordion" style="width:230px"><details class="tui-accordion__item"><summary><span class="tui-accordion__n">01</span>Kitchen<span class="tui-accordion__meta">1.2 kW</span></summary><div class="tui-accordion__body"><p>Oven, hob and the dishwasher.</p></div></details><details class="tui-accordion__item"><summary><span class="tui-accordion__n">02</span>Heat pump<span class="tui-accordion__meta">2.8 kW</span></summary><div class="tui-accordion__body"><p>On its own 20 A circuit.</p></div></details></div>
```

### Flush · the first head under a panel head

```html
<div class="tui-panel" style="width:230px;padding:14px"><div class="tui-panel__head" style="margin-bottom:0"><span class="tui-label">Questions</span></div><div class="tui-accordion tui-accordion--flush"><details class="tui-accordion__item"><summary>Offline?</summary><div class="tui-accordion__body"><p>Yes.</p></div></details><details class="tui-accordion__item"><summary>Who sees it?</summary><div class="tui-accordion__body"><p>You.</p></div></details></div></div>
```

## Every state

- Closed
- Hover
- Open
- Focus

Hover, pressed and focus are forced with `.is-hover`, `.is-down` and `.is-focus`; checked and disabled are real.

## API

| Name | Kind | Values | What it does |
| - | - | - | - |
| .tui-accordion | class | on | The stack: a printed rule above the first section and under each one. |
| .tui-accordion__item | class | on | One section: a head you press and the text it opens. |
| summary | element | first child | The head, at least 52px tall. Its last thing is the key, drawn by the part. |
| name | attribute | any word | Native: sections that share a name close each other, so only one stands open. |
| open | attribute | — | Native: the section starts open and its key starts latched. |
| .tui-accordion__n | class | on | An index printed before the head, 22px wide; the text below lines up with the words. |
| .tui-accordion__meta | class | on | A figure or a status before the key, in the second ink. |
| .tui-accordion__body | class | on | The text. It slides out 6px under the head as it opens. |
| .tui-accordion--flush | class | — | No rule over the first head or under the last: for the inside of a panel. |
| toggle | event | native | Fired on the after it opens or closes; read .open. |
| Enter · Space | keyboard | — | Open or close the section whose head has focus. |
| Tab · Shift+Tab | keyboard | — | Move from head to head, and into an open section’s links. |
| .is-hover · .is-down · .is-focus | class | on summary | Forced states, for documentation and specimens only. |

## Markup

```html
<div class="tui-accordion">
  <details class="tui-accordion__item" name="faq" open>
    <summary><span class="tui-accordion__n">01</span>What does the hub measure?</summary>
    <div class="tui-accordion__body"><p>Every circuit on the board, once a second.</p></div>
  </details>
  <details class="tui-accordion__item" name="faq">
    <summary><span class="tui-accordion__n">02</span>Does it work offline?</summary>
    <div class="tui-accordion__body"><p>Yes. The hub keeps the schedule itself.</p></div>
  </details>
</div>
```

The demo on the page:

```html
<div class="tui-panel" style="width:min(100%,540px)"><div class="tui-accordion">
  <details class="tui-accordion__item" name="acc-demo" open><summary><span class="tui-accordion__n">01</span>What does the hub measure?</summary><div class="tui-accordion__body"><p>Every circuit on the board, once a second: power, energy, and which way it is flowing. The readings stay on the hub; the app asks it for them.</p></div></details>
  <details class="tui-accordion__item" name="acc-demo"><summary><span class="tui-accordion__n">02</span>Does it work without the internet?</summary><div class="tui-accordion__body"><p>Yes. The hub keeps the schedule and the battery rules itself. Away from home you lose the app, and nothing else.</p></div></details>
  <details class="tui-accordion__item" name="acc-demo"><summary><span class="tui-accordion__n">03</span>How long does the battery last in a power cut?</summary><div class="tui-accordion__body"><p>With the reserve at 20% and the fridge, the router and the lights on, about nine hours. Raise the reserve under Battery to keep more back.</p></div></details>
  <details class="tui-accordion__item" name="acc-demo"><summary><span class="tui-accordion__n">04</span>Who can see my readings?</summary><div class="tui-accordion__body"><p>You, and anyone you invite. Nothing leaves the house unless you turn on the monthly report.</p></div></details>
</div></div>
```

## Usage notes

Click a head, or Tab to it and press Enter or Space. Opening one closes the others: they share a name.

## Accessibility

- Native `<details>` and `<summary>`: each head is announced as a button that is expanded or collapsed, with no script at all.
- The shared `name` is the browser’s own exclusive accordion; with no name, several sections can be open.
- Keep links and keys out of the head: it is already a button. Put them in the body.
- Keyboard: Tab reaches each head, and Enter or Space opens or closes its section. That is the browser’s own behaviour for a summary; the kit adds no keys of its own.
- The key is drawn, not announced; the open state is carried by the element itself. Reduced motion drops the slide and keeps the text.

## How it’s built

No script and no extra markup for the key: it is the summary’s `::after`, a 22px cap on a 1.5px skirt whose background is four layers (two ink bars for the +, the key’s top light and its face). Opening swaps the stack for three layers (the vertical bar goes, so it reads −) and gives it the pressed shadow and a 1.5px drop. The body arrives with a 200ms, 6px slide and a fade, on transform and opacity only.

## Rules

Sections of one subject that people read a few of. Name the group when only one should stand open.

The full rules are in `accordion.rules.md` in the brain, which ships with the Kit.

## Related parts

- [Panel](https://tactileui.dev/parts/panel): A face plate that groups what belongs together: a head, a rule, then the parts. Screws only on device-like panels.
- [Tabs](https://tactileui.dev/parts/tabs): Views of the same thing, switched in place: keys in a tray, the chosen view a raised cap.
- [Key](https://tactileui.dev/parts/key): Every button, and every link that acts like one: a cap on a skirt that drops below the plate when pressed.
