BudiBadu Logo
Samplebadu

Markdown by Example: Lists

CommonMark / GFM

Markdown supports ordered and unordered lists. This sample demonstrates how to create and nest them.

Code

Unordered List:
- Item 1
- Item 2
  - Subitem 2a
  - Subitem 2b
* Item 3 (Asterisks work too)
+ Item 4 (Plus signs work too)

Ordered List:
1. First item
2. Second item
3. Third item
   1. Indented item
   2. Indented item

Loose List (paragraphs inside items):
- This item has a paragraph.

  It continues here.

- Next item.

Explanation

Unordered lists can be created using hyphens -, asterisks *, or plus signs +. You can mix them, but it's best to be consistent. Ordered lists use numbers followed by periods, like 1.. Interestingly, the actual numbers don't matter; you could write 1. for every item, and Markdown will still render them as 1, 2, 3... This makes reordering lists easy.

To nest lists, you simply indent the sub-list. The standard indentation is 4 spaces or 1 tab. Some parsers accept 2 spaces, but 4 is the safest bet for compatibility. Nested lists can mix types (e.g., an ordered list inside an unordered one).

If you put blank lines between list items, Markdown creates a "loose list". In a loose list, the content of each item is wrapped in a paragraph tag <p>, adding vertical spacing. In a "tight list" (no blank lines), there are no paragraph tags, and the list looks more compact.

Code Breakdown

4
Indentation (spaces) creates the nested structure.
10
1. The number used in the source doesn't have to match the output order.