Markdown Collapsible Section: Details and Summary

November 11, 2026 · 8 min read

Markdown Collapsible Section: Expandable Content

A markdown collapsible section is built from two HTML elements, <details> and <summary>. The summary line stays visible, and everything else in the block stays hidden until a reader clicks it. It works on GitHub, GitLab and any other renderer that lets raw HTML through, so it's the standard way to fold long content.

How Do You Create a Collapsible Section in Markdown?

Markdown has no syntax of its own for folding content. You write the HTML <details> element and put a <summary> inside it as the clickable label:

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

This content is hidden by default.
You can include **any Markdown** here.

- Lists work
- Links work
- Code blocks work

</details>

The reader sees only "Click to expand" next to a small triangle. A click reveals the rest, and a second click hides it again. It works from the keyboard too: focus the summary and press Space to toggle it.

The HTML details tag is a standard part of HTML, as MDN documents, so no extension or plugin is involved.

Leave a blank line after the </summary> line. An HTML block that starts with a tag such as <details> or <summary> runs until the next blank line, so without one the parser treats your Markdown as part of the HTML and prints the asterisks as they are. GitHub doesn't need a blank line before </details>, but GitLab's docs ask for one, so we add both.

Collapsible Section That Starts Open

Add the open attribute when the section should be expanded on load:

<details open>
<summary>Installation steps</summary>

1. Download the release.
2. Run the installer.

</details>

Readers see the steps straight away and can fold them once they're done. That suits content most people need once, such as setup notes or a changelog for the current version.

Collapsible Code Blocks and Logs on GitHub

On GitHub, a collapsible section uses the same two tags. GitHub's docs suggest it for technical detail that not every reader wants. The usual case is a long code block or log in an issue:

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

```
Error: Cannot find module 'express'
    at Function.Module._resolveFilename
    at Function.Module._load
```

</details>

The fenced block goes inside the <details> block with a blank line above and below it. The issue stays short, and maintainers who need the log open it.

Tables fold the same way, which is handy for the environment details in a bug report:

<details>
<summary>Environment</summary>

| Software | Version |
|---|---|
| Node.js | 22.11.0 |
| OS | Ubuntu 24.04 |

</details>

The same pattern works for a FAQ in a README. Give each question its own block. Readers can then open one answer without scrolling past the others:

<details>
<summary>How do I install this?</summary>

Run the install command from the Quick Start section.

</details>

<details>
<summary>Is it free?</summary>

Yes. The project is MIT licensed.

</details>

Our README Markdown guide covers where sections like these belong in a project README.

Can You Nest Collapsible Sections?

Yes. Put one <details> block inside another, and keep the blank lines around each level:

<details>
<summary>Chapter 1</summary>

Intro text for chapter 1.

<details>
<summary>Section 1.1</summary>

Detail for section 1.1.

</details>

</details>

Each level opens and closes on its own. We prefer to stop at two levels. By the third, readers lose track of which triangle they opened, and a heading with a short list usually does the job better.

Where Do Collapsible Sections Work?

The element only works where the renderer keeps raw HTML. Chat apps show the tags as literal text, and some static site generators need a setting first.

PlatformWorks?Notes
GitHubYesREADMEs, issues, pull requests and comments
GitLabYesGitLab's docs ask for blank lines around the Markdown inside
VS Code previewYesThe built-in Markdown preview renders it
DocusaurusYesRenders as a styled box, as our Docusaurus Markdown guide shows
ObsidianPartlyFolds only when the block has no blank lines, and Markdown inside isn't rendered. A folded callout is the native option
HugoAfter a settingRaw HTML is off by default; turn on Goldmark's unsafe option
Jekyll (kramdown)Yes, with an attributeMarkdown inside stays raw unless you write <details markdown="1">
Slack, DiscordNoNeither has HTML in its message formatting
NotionNoUse Notion's own toggle block instead

The Hugo default comes from its markup configuration, where markup.goldmark.renderer.unsafe is false until you change it. The Obsidian limits come from Obsidian's help page on HTML. If your content has to read well everywhere, keep in mind that a renderer without HTML support either prints the tags as text or strips them, so the content is always visible.

Styling Collapsible Sections

The default look is plain: a triangle and the summary text. On your own site you can style both elements with CSS:

details {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 16px;
}

summary {
  font-weight: 600;
  cursor: pointer;
}

details[open] summary {
  margin-bottom: 12px;
}

The details[open] selector matches only an expanded block, which lets you add spacing or a divider under the label while it's open.

This is limited to sites where you control the stylesheet. GitHub applies its own styles to rendered Markdown, so a collapsed section there always looks the way GitHub draws it.

Common Mistakes with Collapsible Sections

No blank line after the summary. The Markdown below it shows up as raw text, asterisks included. Add an empty line after </summary>.

Markdown inside the summary. Text on the same line as the <summary> tag is HTML, so **Bold title** keeps its asterisks. Use HTML there instead:

<summary><strong>Bold title</strong></summary>

A missing closing tag. Without </details>, everything after the opening tag can end up inside the collapsed block. Close every block you open.

Hiding content people need. A collapsed section is easy to miss, and a reader who skims may never open it. Keep warnings, install commands and breaking changes in plain view.

Try a Collapsible Section in the Editor

Our editor's preview renders <details> and <summary>, so you can test a block before you paste it into a README. Edit the text below and click the summary in the preview:

Collapsible demo

<details> <summary>Click to see the answer</summary>

The answer is 42. This text was hidden until you clicked.

  • Item one
  • Item two

</details>

<details open> <summary>This one starts open</summary>

Click the summary to fold it.

</details>

40 words269 characters18 lines
Markdown

If you'd rather fill in a form, the collapsible section generator builds the block for you. For inline text you want to hide in chat apps, our Markdown spoiler guide lists the syntax each platform uses.

Frequently Asked Questions

A markdown collapsible section needs only two tags, and the rules are short: put the label in <summary>, leave blank lines around the Markdown inside, and close every <details> you open. Use it for logs, long code and optional detail, and keep anything essential visible. Paste your block into the editor to check how it folds before you commit it.