Collapsible sections in Markdown
Markdown has no syntax of its own for collapsible sections, so the standard way is the HTML <details> element with a <summary> line. The summary shows as a clickable line, and the content stays hidden until the reader opens it. It works wherever the renderer allows raw HTML, including GitHub, VS Code's preview and Obsidian.
<details>
<summary>Show the full error log</summary>
The build failed at step 3.
- Missing file: `config.yml`
- Exit code: 1
</details>
Why do I need the blank lines?
The blank line after </summary> and the one before </details> let the content be read as Markdown. Without them, the whole block counts as HTML, and the list above shows its - signs and backticks as typed. This follows the CommonMark rule that an HTML block runs until the next blank line, explained on the HTML in Markdown page.
How do you make a section open by default?
Add the open attribute to the <details> tag. The reader can still close it.
<details open>
<summary>Setup steps</summary>
1. Install the package.
2. Copy the sample config.
</details>
Can you put code blocks or nest sections inside?
Yes to both, as long as the blank lines are there. A fenced code block inside a section is a common way to keep long logs or output out of the way:
<details>
<summary>Output</summary>
```text
Compiled 42 files in 1.8s
```
</details>
Nested <details> blocks also work, each with its own summary. More than two levels gets hard to follow, so headings are usually clearer for deep structure.
Can you style the summary line?
The summary line sits inside the HTML block, so Markdown there, such as **bold**, usually shows its asterisks. Use HTML tags instead: <summary><b>Read more</b></summary> or <summary><code>npm test</code> output</summary>.
Where do collapsible sections work?
| App or spec | <details> |
|---|---|
| CommonMark | Passed through as HTML; folding depends on the viewer |
| GitHub | Yes, in .md files, issues and pull requests |
| VS Code preview | Yes |
| Obsidian | Yes in reading view; callouts can also fold |
| Noteline | Not folded; the content shows as normal text |
Obsidian also has its own foldable callouts. A - after the callout type makes it start closed, and + starts it open:
> [!note]- Click to expand
> Hidden until opened.
Other apps show that as a normal blockquote with the [!note]- text, so it is not portable.
What happens in Word and PDF?
Paper cannot fold. Converters such as Pandoc drop the <details> and <summary> tags when they make Word or PDF files, and the content prints as normal text if the blank lines are there. Without them, the whole block is raw HTML and is usually dropped.
Collapsible sections in Noteline
Noteline does not fold <details> sections. With the blank lines in place, live preview hides the tag lines and shows the content as normal text, and HTML export, printing and the desktop app's Word and PDF export keep the content without the tags. Without the blank lines, the whole block is treated as raw HTML: live preview hides it until the cursor moves onto it, and exports leave it out. The tags stay in the .md file, so the section still folds on GitHub and in Obsidian.
Common questions
Does a collapsed section hide content from search engines?
No. The text is in the page whether the section is open or closed. It only changes what readers see first.
Can I collapse a section under a heading without HTML?
Not in Markdown itself. Some editors, such as Obsidian and VS Code, let you fold headings while you edit, but that only changes your view and does not affect the rendered file.
Why does my details block show the tags?
The renderer does not allow raw HTML, or a tag is misspelled. Check for <summary> directly after <details>.