To create a collapsible section in Markdown on a platform that permits it, wrap the content in HTML <details> and give it a visible <summary> label. Leave blank lines around the inner Markdown blocks. This is an HTML disclosure pattern, not a universal core Markdown feature; confirm that the destination preserves the elements and parses their contents as intended.
1<details>2<summary>Show the example diagnostic log</summary>3
4The export completed with one missing image.5
6</details>The summary stays visible; readers can expand the rest. Use it for optional detail rather than the only copy of a required instruction.
A complete disclosure with a code block
1<details>2<summary>Show the example export log</summary>3
4This log illustrates a missing image reference:5
6```text7Export status: completed8Missing image: images/export-panel.png9Review required: yes10```11
12Check the image path before publishing the exported article.13
14</details>The code block remains literal output, while the explanation is ordinary prose. The blank line after the summary is important for Markdown parsers whose HTML-block handling otherwise consumes following lines as raw HTML.
The GitHub collapsed-section documentation demonstrates supported nested content on GitHub. In another renderer, inspect the actual result: a permitted details element does not automatically prove that the inner Markdown receives the same treatment.
For fence boundaries, use the code-block guide. If the disclosure sits inside a list, its opening tag, contents, and closing tag must also respect the parent item's indentation.
Write a summary that explains what is hidden
Prefer "Show the example export log" to "More" or "Click here." A useful summary answers the reader's question before they spend effort opening it.
Good candidates include a complete request-response example, a lengthy diagnostic log, an optional explanation of a design choice, or an alternate procedure needed by a minority of readers.
Poor candidates include the only warning before deleting data, the required prerequisites for the main task, and the final instruction needed to finish the procedure. Hiding those can make the page appear shorter while making the task harder or riskier.
Keep summaries concise and avoid placing unrelated links or controls inside the clickable label. A disclosure should have one clear toggle target. If the content needs its own navigation tree, it may deserve a separate page instead.
Open by default, and the boolean-attribute trap
In HTML, the presence of open makes a disclosure expanded initially:
1<details open>2 <summary>Review notes</summary>3 <p>These notes are visible on initial load.</p>4</details>Do not use open="false" to close an HTML disclosure. Boolean attributes are enabled by their presence; remove the attribute to start closed. The MDN details reference documents the element and its attributes.
MDX uses JSX and can express a boolean value with open={false}. That is a different source format, not a reason to copy JSX braces into a plain Markdown renderer. If a site provides its own disclosure component, follow that component's props instead.
Opening by default does not make the hidden-content decision irrelevant. The user can still collapse it, and export or print behavior can differ. Critical warnings belong in the main flow even if a disclosure currently starts open.
Accessibility and progressive disclosure
A native disclosure provides a browser-managed toggle instead of requiring a custom click handler. Keep the summary readable, preserve focus visibility, and test keyboard interaction in the final site.
Avoid removing the disclosure marker or outline without providing an equally understandable state indicator. A line of text that looks like an ordinary heading but secretly toggles content is difficult to discover.
Do not assume browser find, deep-link navigation, printing, and exported documents all expose collapsed content identically. If readers need a reliable direct link to a procedure, use a visible heading and table-of-contents link instead of relying on a hidden subsection being automatically opened.
Troubleshoot the source before adding scripts
| Symptom | First check | Likely correction |
|---|---|---|
| HTML tags appear literally | Raw HTML support or a surrounding code fence | Use supported markup outside the fence |
| Asterisks appear inside the open section | Inner content remained in an HTML block | Add appropriate blank-line boundaries and test the parser |
| The rest of the page is inside the disclosure | Missing closing tag | Add the matching </details> |
| The section is open despite "false" | HTML boolean attribute semantics | Remove open for a closed default |
| The toggle is hard to find | Vague label or hidden state marker | Restore a clear summary and visible affordance |
Do not add JavaScript merely because the source has malformed boundaries. First verify a minimal details and summary fixture in the target renderer. Native behavior is usually enough for optional documentation detail.
FAQ
Is a collapsible section standard Markdown syntax?
No. This pattern uses HTML elements embedded in a Markdown document. The destination must permit those elements and handle their contents appropriately.
How do I make the section expanded by default?
In HTML, add the open attribute to details. Remove it for a closed default; the string open="false" does not disable a boolean HTML attribute.
Why does Markdown inside my collapsed section appear as plain text?
The parser may be treating it as raw HTML content. Check blank lines after the summary and around the inner blocks, then verify the renderer's documented HTML behavior.