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
Leave a blank line after </summary> so the Markdown inside renders.Needs HTML<details> <summary>Click to expand</summary> Hidden **Markdown** content. </details>
Starts expanded.Needs HTML<details open>
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.