Tutorial · 7 min read

Markdown Collapsible Sections: Details and Summary Blocks

How to create collapsible sections in Markdown using details and summary blocks, including default-open behavior and renderer support notes.

Orion Wells

Written by

Founder of Aurcue

Founder of Aurcue, writing about AI products, personal style systems, and the decisions behind useful photo-based guidance.

Markdown Collapsible Sections: Details and Summary Blocks

To create a collapsible section in a Markdown file, wrap the optional content in an HTML <details> block and give it a clickable label with <summary>:

<details>
  <summary>Build log</summary>
  The build completed in 42 seconds with no warnings.
</details>

Most Markdown renderers pass these two HTML tags through, so the pattern works in GitHub, GitLab, static site generators, and editors that render safe HTML blocks. The reader sees only the summary line until they click it. This guide covers the exact syntax, the blank-line rule that keeps Markdown inside rendering, default-open behavior, what belongs inside, and where each renderer supports it.

106523d0 6eb2 47f3 a819 dfa77eef567c
Editorial illustration of a Markdown page with one section collapsed to a title and triangle marker and another section expanded to reveal a code fence and a small table

What collapsible sections solve

A collapsible section keeps a document short on screen while the content stays in the file. Common uses:

  • Long logs and stack traces after a short problem statement.
  • FAQ answers so the question list stays scannable.
  • Extended examples that support, but do not block, the main instructions.
  • Changelog details where the headline fits in the summary and the notes expand on click.

Because the section lives in the same file, the content stays portable: anyone opening the Markdown in a plain editor still reads everything, and local AI agents that read raw files see it too. Only the rendered view collapses.

The details and summary block

The <details> element opens or closes on click, and <summary> is its visible label:

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

Without a <summary>, browsers show a generic label such as "Details", so always add one.

The blank-line rule. To keep Markdown inside rendering (headings, lists, code fences), leave a blank line after the closing </summary> tag and a blank line before the closing </details> tag. If a heading or list shows up as raw text, a missing line break after </summary> is usually the cause. A widely used gist on collapsible sections documents the same troubleshooting step.

A worked example with a code fence and a table inside:

<details>
  <summary>Run details</summary>
  ### Build output
  ```text
  Compiling 12 modules... done
StepTime
Compile18.2s
Test9.6s

Two notes on toggle state:

  • The open attribute sets the initial state only. When a reader clicks, the browser toggles the live state; it does not rewrite the file.
  • If you want a section visible by default but collapsible, open is the right tool. If you want content that never renders, use a Markdown comment instead.

Nested Markdown content rules inside details

The indentation and blank-line rules cause most failures in issue threads. Follow these:

  1. Do not indent content as code. Four-space indentation inside <details> can be read as a code block. Keep Markdown content flush left.
  2. Leave a blank line after </summary>. Headings, lists, and fences need it to parse.
  3. Keep the blank line before </details>. Lists that touch the closing tag can be swallowed.
  4. Nested details work. Each level needs its own <summary>:
<details>
  <summary>Section A</summary>
  <details>
    <summary>Section A.1</summary>
    Inner content here.
  </details>
</details>

A checklist inside a details block works too, for example an FAQ checklist that expands on click.

Renderer support table

Not every renderer treats HTML blocks the same way. Check your target before committing to collapsible sections:

RendererDetails and summaryNotes
GitHubSupportedGitHub applies collapse and expand behavior to details elements; Markdown inside renders with the blank-line rule. (discussion)
GitLabSupporteddetails and summary are on the allowlist; Markdown inside is supported with blank lines before and after. (GitLab docs)
Static sites (Jekyll, Hugo, Astro)Usually supportedMost pipelines pass HTML through; strict sanitizers may strip attributes such as open. Verify with a test build.
TyporaNot supportedTypora does not render details blocks; the content shows as raw text. (issue #2570)
ObsidianReading view differsCommunity threads report details blocks do not collapse in Obsidian's reading view. (forum thread)
FyluneSafe MDX blocks render inside the document experienceFylune renders rich Markdown and MDX, including safe HTML blocks, while your files stay ordinary local documents. (product overview)

The same renderer spread explains why a "markdown expandable section" query often returns gists and issue threads instead of one canonical guide: the answer depends on where the file renders. Portable files should still read fine in the collapsed-blind editors, because raw Markdown and hidden HTML remain visible in source view.

When not to hide content behind a toggle

A collapsible section trades visibility for compactness. Do not hide:

  • Required steps. A reader who skips a collapsed install step does not complete the task.
  • Warnings and limits. Safety, licensing, and data-loss caveats should always be visible.
  • Key facts searchers scan for. If most visitors need one sentence, keep it outside the toggle.
  • Content agents must act on. Hidden does not mean removed: agents reading raw files see it, but the rendered view hides it from skimming humans.

Use collapsible sections for supporting depth, not for information the reader must act on.

Quick reference

  • Basic: <details><summary>Label</summary>content</details>
  • Default open: <details open>
  • Markdown inside: blank line after </summary> and before </details>
  • Inside: code fences, tables, lists, images, and nested details
  • Never: required steps, warnings, or facts every reader needs

Organize long notes in Fylune

Fylune is a local-first document workspace for Markdown, MDX, and images. Long notes with logs, FAQ blocks, and extended examples stay ordinary files on your disk, while details blocks render inside the document experience. Download Fylune for macOS and keep working notes, research logs, and docs in one calm workspace.

Sources