Accordion

Questions and answers that open on click.

When to use it

Questions and answers, or any list of short parts a visitor scans before reading one: opening hours by place, the details of a plan.

When not to

Content every visitor must read: hidden text is easy to miss. For a few long parts of equal weight, use tabs; for a guide, use headings and a table of contents.

Accessibility

Each question is a native disclosure (details and summary): it opens with the keyboard, and screen readers say whether it is open. Answers stay in the page, so search engines and the browser's find read them.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The accordion example as the component library shows it in the default theme

Where it is used

The starter sites that use it, each at a page that shows it:

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. Each row is one item, its cells in the order of the fields.

Field

Key

Kind

Required

Question

question

Plain text, one line

Yes

Answer

answer

Text with headings, lists, links and bold

Yes

Variants

This component has no variants of its own; a theme can add some.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table:

accordion

Do I need experience?

No. Every trip has a level, and guides adapt the pace.

What should I bring?

Boots, a rain jacket and a water bottle.

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "accordion",
  "rows": [
    [
      "Do I need experience?",
      "No. Every trip has a level, and guides adapt the pace."
    ],
    [
      "What should I bring?",
      "Boots, a rain jacket and a water bottle."
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

accordion

The component

accordion__answer

A part of it

The HTML the example above writes, as the component library builds it in the default theme:

html
<div class="accordion">
  <details>
    <summary>Do I need experience?</summary>
    <div class="accordion__answer"><p>No. Every trip has a level, and guides adapt the pace.</p></div>
  </details>
  <details>
    <summary>What should I bring?</summary>
    <div class="accordion__answer"><p>Boots, a rain jacket and a water bottle.</p></div>
  </details>
</div>

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/accordion.js
  • src/components/accordion/accordion.liquid