265

I just posted an answer on Stack Overflow where I wanted to have nested numbered lists, something like

1. Dog

1.1. German Shepherd

1.2. Belgian Shepherd

1.2.1. Malinois

1.2.2. Groenendael

1.2.3. Tervuren

2. Cat

2.1. Siberian

2.2. Siamese

As you can see the sublists are not indented, and also "Cat" should be number 2, at the same level as "Dog". I've also tried blockquotes, but still it doesn't work:

  1. Dog

1.1. German Shepherd

1.2. Belgian Shepherd

1.2.1. Malinois

1.2.2. Groenendael

1.2.3. Tervuren

  1. Cat

2.1. Siberian

2.2. Siamese

The first part seems to be indented properly, but then numbering goes wrong again, and indentation too.

So, is there a way to write proper Markdown code for nested number lists?

1
  • 3
    (As an aside: note that any number might create a numbered list, even if its value does not match the expected value. Like a list such as 3., 2., 4. will still be numbered as 1., 2., 3. (by your browser when it encounters <ol><li>Dog</li><li>Cat</li><li>...</li></ol>). Escaping the dot, like by writing 2\., avoids that Markdown recognizes 2. as an item of a (new or existing) numbered list. Hence, writing 2\. Cat would avoid the new list with 1. Cat as its first item, like in your example above.)
    – Arjan
    Commented Mar 31, 2011 at 15:10

7 Answers 7

245

If you're ever stuck on a Markdown question, there's a help button on the right side of the toolbar:

editor help button

That help page explains how to do the simple case:

Advanced lists: Nesting

To put other Markdown blocks in a list; just indent four spaces for each nesting level

For example (see the markdown for this post):

  1. Dog
    1. German Shepherd
    2. Belgian Shepherd
      1. Malinois
      2. Groenendael
      3. Tervuren
  2. Cat
    1. Siberian
    2. Siamese

I think this is as close as you can get; Markdown doesn't support the "1.1.1" type list you wanted

2
  • Using the rendering above, one could still write "1.2.2" in some related text, to refer to "Groenendaal".
    – Arjan
    Commented Mar 31, 2011 at 14:48
  • 2
    the key thing is that each new level of indentation requires 4 spaces (other markdown syntax uses one space for each level. or mediawiki uses * for level 1. ** for level 2 and so on.) Commented May 22, 2018 at 13:27
45
  1. List item
    1.1 List item
  2. List item

If I replace space by _ it gives

_1. List item__  
__1.1 List item
_2. List item

The important thing is the double space after the first item. But so far, I got difficulties with the third level. The only solution I found is adding dots...

  1. Dog
    1.1. German Shepherd
    1.2 Belgian Shepherd
    . . 1.2.1. Malinois
    . . 1.2.2. Groenendael
    . . 1.2.3. Tervuren
  2. Cat
    2.1. Siberian
    2.2. Siamese
13
  • ah! I was sure there was a way! thanks!
    – MarcoS
    Commented Mar 31, 2011 at 14:24
  • @MarcoS see my edit, look like the solution is not that simple.
    – DavRob60
    Commented Mar 31, 2011 at 14:26
  • 13
    You're not actually making a new nesting level, you're just preventing Markdown from recognizing the indented block as a list (that's why the "third" level doesn't work). I don't think markdown supports nested numbered lists of this sort Commented Mar 31, 2011 at 14:30
  • @Michael Mrozek: oh, that's bad news! so, maybe my question should be retagged as feature-request?
    – MarcoS
    Commented Mar 31, 2011 at 14:33
  • @Michael Mrozek you are right, that why I edited this post. your answer is better than mine.
    – DavRob60
    Commented Mar 31, 2011 at 14:34
  • @MarcoS Do you really need the list to say "1.1" instead of just an indented "1."? Commented Mar 31, 2011 at 14:35
  • Actually, @Michael, Markdown kind of supports it, but the CSS is not using double figures for such lists. In the end, the generated HTML is just things like nested <ol>s. One could use CSS counters, but the SE sites don't.
    – Arjan
    Commented Mar 31, 2011 at 14:35
  • 1
    @Arjan Well, Markdown supports nested lists, but I don't think it supports a way to change their type; the only type you can have is the basic "1." at some indentation level Commented Mar 31, 2011 at 14:36
  • @Marco, please only use this if it's REALLY required. The SE content is not only rendered using every day browsers. This is kind of messing up for other usage, like maybe for screen readers, or when using the data dumps or API. (Leading dots could probably be avoided using &nbsp; but then the same applies: you're mixing formatting with content.)
    – Arjan
    Commented Mar 31, 2011 at 14:38
  • (Correct, @Michael, it does not support defining the way lists are rendered or numbered.)
    – Arjan
    Commented Mar 31, 2011 at 14:39
  • @Michael Mrozek: I've seen your answer below. That's sort of a workaround. However, I believe that there are cases in which nested lists are useful. For example, when describing steps of an algorithm using natural language. You may want to refer to a sub-step in your answer (or in other answers or comments) to further comment it.
    – MarcoS
    Commented Mar 31, 2011 at 14:41
  • 1
    @MarcoS, one can still refer to "1.1" in text elsewhere, when the list has "1." on the first level, and "1." in the 2nd level too. It's just a matter of formatting (which is different from what you want), not a matter of "natural language". In fact, when using "1." on the first level, and "1.1" on the second, then maybe one should refer to that item by writing "1.1.1" rather than the "1.1" you're asking for...
    – Arjan
    Commented Mar 31, 2011 at 14:46
  • 2
    @Arjan: yes, you can refer to 1.1 where the first "1" refers to the first level, and the second "1" refers to the second level. However, a nested list as the one showed in Michael Mrozek's answer does not look like the way that people usually expect it. I agree, it's a matter of formatting, but IMHO a traditional nested list is more effective, and, I believe that, although not necessary, it could be nice to have it.
    – MarcoS
    Commented Mar 31, 2011 at 14:55
25

I needed this kind of numbering the list items, so that's how I solved it:

* 1\. item 
    * 1.1\. item
    * 1.2\. item
* 2\. item 

and the result:

  • 1. item
    • 1.1. item
    • 1.2. item
  • 2. item

I know how it looks but I really needed this kind of numbering and presented solutions ware not what I was looking for.

7

I was inspired by DavRob60's attempt at making a faux nested list. Here's a working version.

Result:

 1. Dog
   1.1. German Shepherd: The German Shepherd Dog (GSD, also known as an Alsatian), (German: Deutscher Schäferhund) is a breed of large-sized dog that originated in Germany.
   1.2. Belgian Shepherd
     1.2.1. Malinois
     1.2.2. Groenendael
     1.2.3. Tervuren
 2. Cat
   2.1. Siberian
   2.2. Siamese

Markdown:

&nbsp;1. Dog  
&nbsp;&nbsp;&nbsp;German Shepherd: The German Shepherd Dog (GSD, also known as an Alsatian), (German: Deutscher Schäferhund) is a breed of large-sized dog that originated in Germany.  
&nbsp;&nbsp;&nbsp;1.2. Belgian Shepherd  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2.1. Malinois  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2.2. Groenendael  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.2.3. Tervuren  
&nbsp;2. Cat  
&nbsp;&nbsp;&nbsp;2.1. Siberian  
&nbsp;&nbsp;&nbsp;2.2. Siamese

Note that you have to manually insert line breaks with two trailing spaces on all lines of the list except the last one. You can see this if you highlight the "code."

7
  • 1
    And now try with longer items, like 1.1 German Shepherd: The German Shepherd Dog (GSD, also known as an Alsatian), (German: Deutscher Schäferhund) is a breed of large-sized dog that originated in Germany. and long descriptions like that. @MarcoS, I'd say: try to find a way to answer without the need for odd lists!
    – Arjan
    Commented Mar 31, 2011 at 17:50
  • 2
    I never claimed that this was a good idea. Just pointing out that it is, technically, possible.
    – Pops
    Commented Mar 31, 2011 at 17:51
  • (I know, I'm just trying to convince the OP that it's probably not required for a good answer!)
    – Arjan
    Commented Mar 31, 2011 at 17:53
  • 1
    Nice, +1 for showing what exactly is happening (and to be avoided)!
    – Arjan
    Commented Mar 31, 2011 at 17:57
  • @Popular Demand: nice attempt!
    – MarcoS
    Commented Mar 31, 2011 at 19:07
  • @Arjan: I will survive without nested numbered lists, don't worry :)
    – MarcoS
    Commented Mar 31, 2011 at 19:08
  • 2
    this is awful. nobody wants this
    – pabrams
    Commented Jun 22, 2021 at 15:04
7

This is quite old but there I go. What worked for me was to tab once after each line that is followed by another line.

  1. Item

    1.1. Sub item
    1.2. Sub item

  2. Item

    2.1. Sub item
    2.2. Sub item

5

Nested bulleted lists, deeper levels: ---- leave here an empty row * A item, first level - no space in front the bullet character * Aa item, second level - 1 space is enough * Aaa item, third level - 5 spaces min * Ab item, second level - 4 spaces possible too * B item, first level

Nested bulleted lists, deeper levels:

  • A item, first level - no space in front the bullet character
    • Aa item, second level - 1 space is enough
      • Aaa item, third level - 5 spaces min
    • Ab item, second level - 4 spaces possible too
  • B item, first level

    Nested bulleted lists, deeper levels:
     ...Skip a line and indent eight spaces. (as said in the editor-help, just on this page)
    * A item, first level - no space in front the bullet character
     * Aa item, second level - 1 space is enough
         * Aaa item, third level - 5 spaces min
        * Ab item, second level - 4 spaces possible too
    * B item, first level
    

    Nested numbered lists, deeper levels:
     ...Skip a line and indent eight spaces. (as said in the editor-help, just on this page)
    * 1. item, first level - no space in front the bullet character
     * 1.1. item, second level - 1 space is enough
             * 1.1.1. item, third level - 9 spaces min
            * 1.2. item, second level - 8 spaces possible too
    * 2. item, first level

Nested numbered lists, deeper levels:

    1. item, first level - no space in front the bullet character
      • 1.1. item, second level - 1 space is enough
        • 1.1.1. item, third level - 9 spaces min
      • 1.2. item, second level - 8 spaces possible too
    1. item, first level

Nested numbered lists, deeper levels: ---- leave here an empty row * 1. item, first level - no space in front the bullet character * 1.1. item, second level - 1 space is enough * 1.1.1. item, third level - 9 spaces min * 1.2. item, second level - 8 spaces possible too * 2. item, first level

1
5

Great question; here is one way:

Markdown Numbered SubList

<ul>
  <li>1. First Item</li>
  <li>2. Second Item
    <ul>
    <li>2.1 Second Item Sub Item 1 </li>
    <li>2.2 Second Item Sub Item 2</li>
    <li>2.3 Second Item Sub Item 3</li>
    </ul>
  </li>
  <li>3 Third Item </li>
</ul>

Raw markdown:

<ul>
  <li>1. First Item</li>
  <li>2. Second Item
    <ul>
    <li>2.1 Second Item Sub Item 1 </li>
    <li>2.2 Second Item Sub Item 2</li>
    <li>2.3 Second Item Sub Item 3</li>
    </ul>
  </li>
  <li>3 Third Item </li>
</ul>

Hope this helps

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .