# Accordions

> Tuck optional detail behind a title readers can click to expand. Stack several in a group for FAQs.

An accordion shows a title and hides its content until the reader clicks it. Use it for detail most readers can skip, like FAQs and troubleshooting.

<Accordion title="Which file types can a page use?">
  Pages are `.mdx` or `.md` files. Both take frontmatter for the title and description.
</Accordion>

```mdx
<Accordion title="Which file types can a page use?">
  Pages are `.mdx` or `.md` files. Both take frontmatter for the title and description.
</Accordion>
```

## Description, icon, and open by default

Add a `description` for a line of smaller text under the title, and an `icon` to show a [Heroicons](https://heroicons.com/) icon before it. Set `defaultOpen` to start the accordion expanded.

<Accordion title="Troubleshooting" description="What to check when a request fails" icon="wrench-screwdriver" defaultOpen>
  Check the status code first. A `401` means the API key is missing or wrong.
</Accordion>

```mdx
<Accordion title="Troubleshooting" description="What to check when a request fails" icon="wrench-screwdriver" defaultOpen>
  Check the status code first. A `401` means the API key is missing or wrong.
</Accordion>
```

## Accordion groups

Wrap accordions in `<AccordionGroup>` to put them in one frame with a divider between each. It's the tidiest way to lay out an FAQ.

<AccordionGroup>
  <Accordion title="Can I use my own domain?">
    Yes. Add it in your project settings, then create a CNAME record pointing to `cname.typemark.dev`.
  </Accordion>
  <Accordion title="Can I export my content?">
    Your pages live in a Git repository. Connect it to GitHub to keep a copy in your own account.
  </Accordion>
  <Accordion title="Does the visual editor change my MDX?">
    Not behind your back. Components it has no block for show as read-only source and save back exactly as written.
  </Accordion>
</AccordionGroup>

```mdx
<AccordionGroup>
  <Accordion title="Can I use my own domain?">
    Yes. Add it in your project settings, then create a CNAME record pointing to `cname.typemark.dev`.
  </Accordion>
  <Accordion title="Can I export my content?">
    Your pages live in a Git repository. Connect it to GitHub to keep a copy in your own account.
  </Accordion>
  <Accordion title="Does the visual editor change my MDX?">
    Not behind your back. Components it has no block for show as read-only source and save back exactly as written.
  </Accordion>
</AccordionGroup>
```

## Rich content

The body can hold anything a page can, including code blocks and callouts.

<Accordion title="How do I authenticate requests?">
  Send your API key in the `Authorization` header:

  ```javascript
  const response = await fetch("https://api.acme.com/data", {
    headers: { Authorization: "Bearer sk_live_abc123" },
  });
  ```

  <Callout type="warning">
    Keep the key in an environment variable, not in your source code.
  </Callout>
</Accordion>

## Props

### Accordion

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `title` | string | none | Text in the clickable header. |
| `description` | string | none | Smaller line of text under the title. |
| `icon` | string | none | Heroicons name shown before the title. |
| `defaultOpen` | boolean | `false` | Starts the accordion expanded. |

### AccordionGroup

`<AccordionGroup>` takes no props. Put `<Accordion>` blocks inside it.

## In the visual editor

Type `/` and pick **Accordion**. Edit the title in the header and type the content below it. Props the editor doesn't show, like `description` and `icon`, are kept as you wrote them when you save.

<Callout type="tip">
  Don't hide anything the reader needs to finish the task. If it's essential, it belongs on the page, not in an accordion.
</Callout>
