Indent a Nested List Two Spaces and It Flattens in Some Apps — How Far to Indent So Every Renderer Keeps the Sublist
Four spaces or one tab is the safe indent width for a nested list in Markdown. That width nested in all ten default engines tested — GitHub, pandoc, markdown-it, and Python-Markdown among them. Two spaces works in nine of the ten, but Python-Markdown silently promotes the child into a sibling. Four spaces never surprises you at defaults.1 2
The confusion is old and persistent. A Stack Overflow question asking "How to markdown nested list items in Bitbucket?" has accumulated 557,189 views since it was asked in 2016, and its top answer — with a score of 870 — opens with a single heading: "Use 4 spaces."2 Six related questions about nested-list indentation have drawn a combined 655,204 views.3 The question keeps coming back because the answer depends on which Markdown engine your destination uses, and that is rarely disclosed in a text editor.
What goes wrong looks like this. You write a checklist in your notes app — the sub-steps nest correctly in the editor preview. You publish to your MkDocs documentation site and the sub-steps vanish into the main list. Each sub-step is now a full item, as if you had never indented it at all. The structure was correct. The destination had different rules.
This post explains those rules: where the two-space width comes from, why Python-Markdown requires four, how the minimum changes with the parent marker, and which formatter defaults quietly undo the fix.
Why two spaces nests on GitHub but flattens in MkDocs
Python-Markdown requires four spaces or one tab per nesting level — a rule baked into the library since its early days and explicitly maintained by its authors. CommonMark-family engines accept a narrower indent because they follow the spec's "W + N" rule, where the required depth is tied to the width of the parent marker — not to a fixed four-space threshold.4 5
The CommonMark spec describes the logic this way: "it is certainly reasonable to infer that all block elements under a list item, including other lists, must be indented four spaces."4 But the spec also notes that Markdown.pl itself "allowed paragraphs and sublists to start with only two spaces indentation, at least on the outer level."4 The result: two schools of parsers inherited two different defaults, and neither is wrong by the standard it was designed against.
Python-Markdown's documentation states the rule directly: "They must always be indented by at least four spaces (or one tab) for each level of nesting."5 The library's maintainers view looser behavior as a defect to prevent — not an accommodation to offer. "The implementers of Python-Markdown consider it a bug to not enforce this rule."5
MkDocs, the popular static-site generator used for documentation, runs Python-Markdown by default. Its own documentation states: "MkDocs uses the Python-Markdown library to render Markdown documents to HTML."6 When you write a note or doc and publish it through a default MkDocs site, Python-Markdown's four-space rule applies — not GitHub's.
What Python-Markdown does with a two-space child under - is not simply delete the sublist. It demotes the child to a sibling. - Parent with - child indented two spaces renders as <li>Parent</li><li>child</li> — two items at the same level.1 Under a numbered parent (1. Parent), the two-space bullet child becomes item 2 of the ordered list. The indented sub-step is promoted to a step.
The safe rule — four spaces or a tab
Four spaces or one tab nested in all ten default engines under every parent marker tested: -, 1., and 10.. That includes Python-Markdown, CommonMark parsers, pandoc in its current default mode, and GitHub. Tab works in every case as well — the two are interchangeable at engine defaults.1 2
The CommonMark spec acknowledges the difficulty plainly: "there is no way to give a spec for list items that will be guaranteed not to break any existing documents."4 Different parsers landed on different interpretations. The safest portable choice is the one all of them accept.
The following table summarizes the results for ten default engines — markdown-it 15.0.3, commonmark.js 0.31.2, marked 18.2.0, micromark 4.0.3, markdown-it-py 4.3.0, mistune 3.4.0, pandoc 3.8.3 -f markdown, pandoc 3.8.3 -f commonmark, GitHub POST /markdown mode gfm, and Python-Markdown 3.11.3:1
| Indent | CommonMark family (9 engines) | Python-Markdown default |
|---|---|---|
- / 2 spaces | nested | sibling |
- / 4 spaces | nested | nested |
1. / 2 spaces | separate list | becomes item 2 |
1. / 3 spaces | nested | flat |
1. / 4 spaces | nested | nested |
10. / 3 spaces | separate list | flat |
10. / 4 spaces | nested | nested |
| tab (any marker) | nested | nested |
The pattern holds without exception. Four spaces or one tab is the only width that nested in all ten defaults for all three marker types.
Marker width changes the minimum
The marker's width sets the minimum useful indent. Under -, two spaces lands past the bullet and suffices for CommonMark. Under 1., that same two spaces lands before the text begins — all ten engines treat the child as a new list. Under 10., three spaces also fails: the text starts at column five, so the child needs four.1 2
The CommonMark spec describes the underlying principle as the "W + N" rule: a child block must be indented by W + N spaces, where W is the width of the list marker and N is the number of spaces between the marker and the first content character.4 For - followed by one space, W + N = 2. For 1. followed by one space, W + N = 3. Four spaces exceeds both thresholds — which is why four is the portable default.
John Gruber's original Markdown syntax document states the four-space-or-tab rule for continuation paragraphs in list items — not specifically for sublists.7 The spec's authors are careful to note that the four-space rule for sublists is "reasonable to infer" rather than explicitly mandated by Gruber.4 Python-Markdown and pandoc's historical default both enforced the four-space rule strictly; pandoc has since moved to CommonMark-style behavior as its default, treating the stricter rule as an opt-in extension named four_space_rule.8 2
The earlier post on parsing Markdown edge cases that break editors covers the broader family of cases where 1. list behavior diverges across parsers — including where the CommonMark family agrees on a result that Python-Markdown does not share. Indentation is a separate dimension from numbering, but the same parser variation that affects one tends to affect the other. The post on the number you type in a Markdown list being only a suggestion covers the numbering side; this post owns the indent side.
How to fix your nested list in three steps
Indent the child item so it lines up with where the parent's text starts, then add two more spaces as a safety margin. For -, that is four spaces. For 1., that is four spaces. For 10., that is four spaces. If the list will be published to a MkDocs site, use four spaces regardless of the parent marker — or one tab.1
Step 1 — Write the parent item normally.
- Parent item
Step 2 — Indent the child by four spaces (or one tab).
- Parent item
- Child item
Both four spaces and a tab work in all ten tested defaults. If you use a tab, verify that your editor does not expand it to two spaces on save — many do, and the expansion happens silently.
Step 3 — Extend the same rule to deeper levels.
Each additional level adds another four spaces — or another tab. A three-level list under - needs four spaces for the second level and eight for the third:
- Level 1
- Level 2
- Level 3
A three-level list indented at two spaces per level nests two deep in nine of ten engines. Python-Markdown nests it only one deep: the second-level child becomes a sibling, and the third-level item at four spaces nests under it.1
Check in the destination renderer. The clearest test is to open the document in the renderer your site or tool actually uses — not in your editor's preview. Many editors use CommonMark parsers for their preview pane. An earlier post on drawing a directory tree in Markdown made the same observation: a note can look correct in one context and render differently in another, with Python-Markdown flattening what CommonMark-family engines nested correctly.
The settings traps — when your formatter undoes the fix
Prettier 3 and markdownlint's ul-indent rule (MD007) both default to two-space indents and silently rewrite a four-space child to the marker width on save. If your repository runs either tool at defaults, Python-Markdown will flatten the child after the rewrite. The fix is to configure the formatter to match the destination renderer — not the other way around.9 10
Prettier 3.10.1 rewrites list indentation to match the marker width on --parser markdown with defaults: - children go to two spaces, 1. children go to three, 10. children go to four.9 After that rewrite, a document that rendered correctly in Python-Markdown now has two-space - children — which Python-Markdown demotes to siblings.
The post on formatters that break note syntax covers the broader pattern: a formatter optimizing for one standard can silently invalidate markup for another. List indentation is one of the cleaner examples — the failure is deterministic and the fix is a configuration line.
The commonly suggested workaround for Python-Markdown's strictness is an extension. The mdx_truly_sane_lists package (version 1.3) sets nested_indent: 2 by default: "Custom indent for nested lists. Defaults to 2."11 At that setting, four-space and tab children in six tested cases produce literal text rather than a nested list — the four-space child is emitted inside the parent <li> as a raw string. The Python-Markdown maintainers have noted the trade-off directly: "Python Markdown is also an old-school Markdown parser, not a CommonMark parser," and "I also don't know if they have other side effects."12
The tab_length=2 setting in Python-Markdown reinterprets four-space children as deeper than expected — under that setting, two-space children nest but four-space children do not.1 5 The documentation warns: "tab_length can be set to whatever length is desired. Be warned however, as this will affect indentation for all aspects of the syntax (including root level code blocks)."5
The practical rule is narrow. If your destination runs Python-Markdown at defaults — as most MkDocs sites do — use four spaces, pin your formatter to honor that choice, and leave mdx_truly_sane_lists aside unless you are willing to adjust every four-space child already in the document. And note the separate case: four spaces after a blank line outside a list creates a code block — not a sublist. The post on what Markdown throws away when it ignores your extra spaces covers that boundary. Inside a list item, the same four spaces nest. The difference is context — blank-line boundary versus direct continuation.
How this applies to your notes
If you write notes in Markdown and open them in multiple apps or publish them to a static site, the safest habit is four spaces or a tab for every nested level. That width keeps the structure intact as the note moves from one renderer to the next — which is exactly what portable Markdown files are supposed to do.1
The specific advice: use four spaces in every nested list, configure any formatters to preserve that, and test in the actual destination renderer rather than the editor preview. That combination — consistent indentation, configured tools, and destination-side verification — is the only approach that holds across all ten default engines tested.
A note stored as a plain Markdown file on your own device keeps its structure as written. The indentation is literal characters — nothing a sync service or export function transforms. The only variable is the renderer that opens it next.
Frequently Asked Questions
How many spaces should I use to indent a nested list in Markdown?
Four spaces or one tab. That width nested in all ten default Markdown engines tested under every parent marker — -, 1., and 10.. Two spaces works in nine of ten at defaults, but Python-Markdown (used by a default MkDocs site) promotes a two-space child to a sibling instead of nesting it.1
Why does my nested list not indent in MkDocs?
A default MkDocs site uses Python-Markdown, which requires four spaces or one tab per level. Python-Markdown does not follow the CommonMark "W + N" rule that most editors and GitHub use.5 6 If your child items are indented by two spaces, Python-Markdown renders them as siblings at the parent level rather than as a sublist.
Does a tab work for nested lists in Markdown?
Yes. A tab character nested in all ten default engines tested, under all three parent marker types (-, 1., 10.).2 The tab is treated the same as four spaces in every default configuration. The exception is mdx_truly_sane_lists with its default nested_indent: 2 setting, where tabs under - are also demoted.1
How do I nest a numbered list inside a bullet list?
Use four spaces before the numbered item. The parent marker type does not affect how the child is indented — the four-space rule holds for mixed list types in all ten tested defaults. Example: - Parent item / 1. Child numbered item.
Why does the same Markdown look correct in my editor but wrong when published?
Most editor previews use a CommonMark-compatible parser. If you publish to a site running Python-Markdown — a default MkDocs site, for example — the two parsers have different rules for nested-list indentation.4 5 A two-space indent passes CommonMark and fails Python-Markdown. The fix is to use four spaces in the source file so both parsers agree.
Will four spaces ever create a code block instead of a list indent?
Inside a list item, four additional spaces signal a sublist. Outside a list item — after a blank line — four spaces create a code block. The context determines the interpretation.13 Keep the child item directly under the parent with no blank line between them, and the four spaces nest rather than code-block.
What happens if my formatter keeps changing the indentation back to two spaces?
Prettier 3 and markdownlint MD007 both default to two-space list indentation and rewrite deeper indents on save.9 10 Set markdownlint MD007's indent option to 4 to match the destination renderer. Without that configuration, the formatter will undo the fix on every pass.
Does three spaces work for 1. lists?
Three spaces works for 1. in nine of ten tested engines — all CommonMark-family parsers plus GitHub. Python-Markdown requires four and treats three as a sibling.1 For 10., three spaces fails in all ten engines because the text starts at column five, past the three-space threshold.
The indent width for a nested Markdown list is not a formatting preference — it is a compatibility decision. Four spaces or one tab is the only width that nested in all ten default engines tested.
If you keep notes in Markdown across multiple tools, mnmnote.com stores every note as a portable file on your own device — the same Markdown that opens anywhere.
References
Footnotes
-
Own receipt 261114 — 11 cases × 10 default engines (markdown-it 15.0.3, commonmark.js 0.31.2, marked 18.2.0, micromark 4.0.3, markdown-it-py 4.3.0, mistune 3.4.0, pandoc 3.8.3
-f markdown, pandoc 3.8.3-f commonmark, GitHubPOST /markdownmodegfm, Python-Markdown 3.11.3), plusmdx_truly_sane_lists1.3,tab_length=2, and Prettier 3.10.1 · accessed 2026-11-14 ·materials/receipt-261114.txt. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8 ↩9 ↩10 ↩11 ↩12 -
Stack Overflow Q37575916 — "How to markdown nested list items in Bitbucket?" · asked 2016-06-01 · 557,189 views · accepted answer score 870 · accessed 2026-11-14 · https://stackoverflow.com/questions/37575916 ↩ ↩2 ↩3 ↩4 ↩5 ↩6
-
Stack Exchange API, batch query for six nested-list questions (ids 37575916, 50163820, 31039189, 51573722, 47896937, 21988073) · accessed 2026-11-14 · combined view count 655,204. ↩
-
CommonMark Spec 0.31.2, §5.2 List items (Motivation) · 2024-01-28 · https://spec.commonmark.org/0.31.2/#list-items · archived https://web.archive.org/web/20261114012548/https://spec.commonmark.org/0.31.2/ ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7
-
Python-Markdown, "Differences" · https://python-markdown.github.io/#differences · archived https://web.archive.org/web/20261114012606/https://python-markdown.github.io/ ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7
-
MkDocs, Writing your docs · https://www.mkdocs.org/user-guide/writing-your-docs/ · archived https://web.archive.org/web/20261114012625/https://www.mkdocs.org/user-guide/writing-your-docs/ ↩ ↩2
-
John Gruber, Markdown: Syntax · 2004 · https://daringfireball.net/projects/markdown/syntax · archived https://web.archive.org/web/20261114012644/https://daringfireball.net/projects/markdown/syntax ↩
-
Pandoc User's Guide,
Extension: four_space_rule— "Selects the pandoc <= 2.0 behavior for parsing lists, so that four spaces indent are needed for list item continuation paragraphs." · https://pandoc.org/MANUAL.html · archived https://web.archive.org/web/20261114012702/https://pandoc.org/MANUAL.html ↩ -
Prettier 3.10.1,
--parser markdowndefaults · released 2026-11-12 per npm · own receipt 261114. ↩ ↩2 ↩3 -
markdownlint MD007
ul-indent— "This rule is triggered when list items are not indented by the configured number of spaces (default: 2)." · markdownlint 0.42.1 · https://github.com/DavidAnson/markdownlint/blob/main/doc/md007.md · archived https://web.archive.org/web/20261114012740/https://github.com/DavidAnson/markdownlint/blob/main/doc/md007.md ↩ ↩2 -
mdx_truly_sane_lists README,
nested_indentoption · https://github.com/radude/mdx_truly_sane_lists · archived https://web.archive.org/web/20261114012722/https://github.com/radude/mdx_truly_sane_lists · package 1.3 uploaded 2022-07-19 (PyPI). ↩ -
Python-Markdown issue #1378, maintainer comments by Waylan Limberg (2023-08-22) and facelessuser (2024-09-09) · https://github.com/Python-Markdown/markdown/issues/1378 · archived https://web.archive.org/web/20261114012911/https://github.com/Python-Markdown/markdown/issues/1378 ↩
-
Stack Overflow Q21988073 — "Create nested list and not code block in markdown" · accessed 2026-11-14 via Stack Exchange API. ↩