# Accordions for Ghost

HTML card + code injection · Works with any Ghost theme · No JavaScript

Source: https://brightthemes.com/snippets/accordions

Collapsible sections for FAQs and long posts, built on the browser's own details element, so they open with a mouse, a keyboard or a screen reader and need no JavaScript.

## When to use it
- An FAQ at the end of a pricing or membership post, where readers scan for their one question.
- A tutorial's troubleshooting section, one fix per error message, so readers open only the one they hit.
- Answers to the exercises in a lesson or quiz post, which readers open once they've tried.
- The practical details of a course or event (refunds, access, schedule) that most readers skip.
When not to: For one hidden answer, or a post you send as a newsletter, Ghost's **Toggle** card is simpler and needs no code.

## The code

HTML:

```html
<div class="bt-accordion-group">
  <details class="bt-accordion" name="faq" open>
    <summary>When does my subscription start?</summary>
    <div class="bt-accordion-body">
      <p>Right away. As soon as you confirm your email, you have access to every post on your plan, and the first newsletter arrives with the next issue.</p>
    </div>
  </details>

  <details class="bt-accordion" name="faq" style="--bt-accordion-accent: #0f766e;">
    <summary>I forgot my password. How do I sign in?</summary>
    <div class="bt-accordion-body">
      <p>You don't need one. Choose Sign in, enter your email, and we'll send you a link that signs you in on that device.</p>
    </div>
  </details>

  <details class="bt-accordion" name="faq">
    <summary>How do I change or cancel my plan?</summary>
    <div class="bt-accordion-body">
      <p>Open your account from the site's menu. You can switch between monthly and yearly plans or cancel there; a canceled plan stays active until the end of the period you paid for.</p>
    </div>
  </details>
</div>
```

CSS:

```css
.bt-accordion {
  --bt-accordion-accent: var(--ghost-accent-color, #4433ff);
  --bt-accordion-tint: 8%;
  --bt-accordion-radius: 6px;
  margin: 0 0 1em;
  border-left: 4px solid var(--bt-accordion-accent);
  border-radius: var(--bt-accordion-radius);
  background-color: color-mix(in srgb, var(--bt-accordion-accent) var(--bt-accordion-tint), transparent);
}

.bt-accordion > summary {
  display: flex;
  gap: 0.75em;
  padding: 1em 1.25em;
  font-weight: 600;
  line-height: 1.5;
  list-style: none;
  cursor: pointer;
  border-radius: var(--bt-accordion-radius);
}

.bt-accordion > summary::-webkit-details-marker {
  display: none;
}

.bt-accordion > summary::before {
  flex: none;
  width: 0.8em;
  font-size: 1.4em;
  line-height: 1.07;
  text-align: center;
  font-weight: 400;
  content: '+';
  content: '+' / '';
  transition: transform 0.2s ease;
}

.bt-accordion[open] > summary::before {
  transform: rotate(45deg);
}

.bt-accordion > summary:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.bt-accordion-body {
  padding: 0 1.25em 1em 3.1em;
}

.bt-accordion-body > :first-child {
  margin-top: 0;
}

.bt-accordion-body > :last-child {
  margin-bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
  .bt-accordion > summary::before {
    transition: none;
  }
}
```

## Add it to your site

1. Copy the **CSS** and paste it in **Settings › Advanced › Code injection › Site header**, between `<style>` and `</style>`. Once per site.
2. In a post, add an **HTML card** (type `/html`) and paste the **HTML**.
3. Change the example text to your own, then publish or update the post.

Tip: save the card as a Ghost snippet to add it to any post from the card menu: how Ghost snippets work, https://brightthemes.com/blog/ghost-snippets

## How it works

Each question is a `<details>` element with a `<summary>`, the browser's own disclosure widget, so the browser does the opening and closing. The CSS only restyles it: a plus in place of the default triangle, turning into a cross when open, and a border and a light tint in your accent color. The text keeps your theme's color, so it fits light and dark themes.

The questions share `name="faq"`, so opening one closes the others. Remove the `name` to let readers open several at once, and give each group on a page its own name. Add `open` to a `<details>` to show it open when the page loads.

Ghost's editor has its own **Toggle** card, one collapsible section with no code, which also works in newsletters. Use it for a one-off question; use this snippet for a styled group, such as an FAQ, with one question open at a time. The CSS from code injection doesn't reach emails, so in a newsletter these show as plain, unstyled sections. See [how editor cards work in Ghost](https://brightthemes.com/blog/ghost-editor-cards) and [how code injection works](https://brightthemes.com/blog/ghost-code-injection).

## Customize
| Variable | Default | What it changes |
|---|---|---|
| `--bt-accordion-accent` | `var(--ghost-accent-color, #4433ff)` | The color of the left border and the background tint. Defaults to your site's accent color; set it on one bt-accordion's style attribute to change only that one. |
| `--bt-accordion-tint` | `8%` | How much of the accent color tints the background. 0% for no background. |
| `--bt-accordion-radius` | `6px` | The corner radius. |

It works with every Ghost theme, including ours (https://brightthemes.com/themes). Something not right? Ask support: https://brightthemes.com/support
