MDConverter
Universal In-Browser Converter
100% Client-Side Private

How to Make a Collapsible Section in Markdown

By the MDConverter team · Updated · 2 min read

Quick answer

Markdown has no collapse syntax, so use HTML: wrap the content in <details> and put the clickable label in <summary>. Leave a blank line after </summary> and before </details> so the content inside is processed as Markdown. Add open to start expanded. It works on GitHub, GitLab, VS Code, most documentation sites and anywhere HTML is allowed.

Basic syntax

The <summary> text is always visible; the rest appears when the reader clicks it.

Markdown
<details>
<summary>Installation steps</summary>

1. Download the installer
2. Run `setup.exe`
3. Restart your computer

</details>
Result
Installation steps
  1. Download the installer
  2. Run setup.exe
  3. Restart your computer
Click “Installation steps” in the result to expand it. The blank lines around the content are what let the list render as Markdown.

Expanded by default

Add the open attribute to show the content until the reader collapses it.

Markdown
<details open>
<summary>Release notes</summary>

- **Added:** dark mode
- **Fixed:** login redirect

</details>
Result
Release notes
  • Added: dark mode
  • Fixed: login redirect

Code blocks and nested sections

Fenced code works inside, and <details> blocks can be nested — useful for long logs and FAQs.

Markdown
<details>
<summary>Error log</summary>

```text
TypeError: Cannot read properties of undefined
    at render (app.js:42:13)
```

<details>
<summary>Environment</summary>

Node 22, macOS 15

</details>

</details>
Result
Error log
TypeError: Cannot read properties of undefined
    at render (app.js:42:13)
Environment

Node 22, macOS 15

Formatting the summary line

Markdown inside <summary> is not processed by most renderers. Use HTML tags instead: <summary><b>Bold label</b></summary> or <summary><code>config.yaml</code></summary>. A heading inside the summary (<summary><h3>…</h3></summary>) works on GitHub but makes the arrow sit on its own line.

Alternatives in apps without HTML

  • Obsidian: foldable callouts — > [!note]- Title starts collapsed, > [!note]+ Title starts open. Headings can also be folded in the editor.
  • Discord: ||spoiler|| hides text until clicked (inline only).
  • Notion: toggle blocks, created by typing > at the start of a line.

Where <details> works

AppSupportedNotes
GitHubYesREADMEs, issues, PRs, comments and wikis.
GitLab, BitbucketYesSupported in Markdown files and descriptions.
VS Code preview, MkDocs, DocusaurusYesMkDocs Material also offers ??? collapsible admonitions.
ObsidianPartlyRenders <details>, but Markdown inside it is not processed; use foldable callouts.
Reddit, Discord, SlackNoHTML is not allowed.
NotionNoUse a toggle block instead.

Common mistakes and how to fix them

ProblemFix
Markdown inside shows as raw textAdd a blank line after </summary> and before </details>.
The whole page after the section is hiddenYou forgot the closing </details> tag.
Bold in the summary shows asterisksUse <b> or <strong> inside <summary>.

Tools for this

Frequently Asked Questions

Frequently Asked Questions About Collapsible sections

Comprehensive answers to common technical, formatting, security, and compatibility questions.

Not in CommonMark or GitHub Flavored Markdown. The standard approach is the HTML <details> and <summary> elements, which Markdown allows inline. Some tools add their own syntax, such as Obsidian’s foldable callouts or MkDocs’ ??? admonitions.

Sources

← All Markdown lessons · Markdown cheat sheet