Skip to content
All Markdown syntax

Collapsible sections in Markdown

Blocks

Markdown syntax

Needs HTML
<details>
<summary>Click to expand</summary>

Hidden **Markdown** content.

</details>

Leave a blank line after </summary> so the Markdown inside renders.

Markdown has no folding syntax, but the HTML <details> element works on GitHub, GitLab and most editors that allow HTML. The <summary> line is what readers click; everything after it is hidden until then.

All ways to write it

  • <details>
    <summary>Click to expand</summary>
    
    Hidden **Markdown** content.
    
    </details>
    Leave a blank line after </summary> so the Markdown inside renders.Needs HTML
  • <details open>
    Starts expanded.Needs HTML

Example

You type

<details>
<summary>Full error log</summary>

```
Error: page title already exists in space DOCS
```

</details>

You get

Full error log
Error: page title already exists in space DOCS

Click the summary line in the preview to open it.

Questions

Why is the Markdown inside <details> not formatted?

Add a blank line after </summary> and before </details>. Without it, the content is treated as HTML.

Can I nest collapsible sections?

Yes, a <details> can sit inside another one.

Collapsible section in Confluence

Confluence's Expand element does this on a normal page. Markdown Exporter includes Expand macros in its export, so their content comes out with the rest of the page.

Related syntax

Also in Blocks

See all Markdown syntax