1.

Lists

Answer»

There are 2 types of lists we can add in markdown,

1. Ordered Lists:


  • An ordered list defines a list of items in which the order of the items matter.

  • Syntax:

1. Element 1
2. Element 2
3. Element 3

Output:


  1. Element 1

  2. Element 2

  3. Element 3


  • Ordered List with Sublists:

    • Lists can be nested into sublists to include items that are a part of a longer list. The example below shows how to implement nested unordered lists in markdown.

    • Syntax:


1. Level 1
1. Level 2
- Level 3
- Level 4
2. Level 1
1. Level 2
3. Level 1
1. Level 2

Output:


  1. Level 1
    1. Level 2

      • Level 3

      • Level 4




  2. Level 1
    1. Level 2


  3. Level 1
    1. Level 2


2. Unordered Lists:

We can create unordered lists with an asterisk(*), (+), or (-) signs as shown below:

  • With asterisk(*):
* Element 1
* Element 2
* Element 3

Output: 


  • Element 1


  • Element 2


  • Element 3


  • With plus(+):
+ Element 1
+ Element 2
+ Element 3

Output: 


  • Element 1


  • Element 2


  • Element 3


 

  • With minus(-):
- Element 1
- Element 2
- Element 3

Output:


  • Element 1


  • Element 2


  • Element 3


3. Nested Unordered Lists:

Unordered Lists can also be nested into multiple sublists beneath them similar to ordered lists. The example below shows how to implement nested unordered lists in markdown.

Syntax:

- Level 1
- Level 2
- Level 3
- Level 4
- Level 1
- Level 2
- Level 1
- Level 2

Output:


  • Level 1
    • Level 2
      • Level 3
        • Level 4




  • Level 1
    • Level 2


  • Level 1
    • Level 2


List using HTML:

We can create lists in the following way by using the HTML tags as shown below:


  • Ordered List:

    • We can also create ordered lists in markdown using the HTML <ol></ol> tags. The <ol></ol> tags denote the start and end of the lists. The items in the list are added using the <li></li> tags.

    • Syntax:


<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ol>

Output:


  1. First item

  2. Second item

  3. Third item

  4. Fourth item


  • Unordered List:

    • We can also create unordered lists in markdown using the HTML <ul></ul> tags. The <ul></ul> tags denote the start and end of the lists. The items in the list are added using the <li></li> tags.

    • Syntax:


<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
<li>Fourth item</li>
</ul>

Output:


  • First item

  • Second item

  • Third item

  • Fourth item

Creating Task Lists:

We can also create task lists in markdown using a hyphen(-) followed by [ ] braces. An x is put inside the braces to indicate the task is complete.

Example:

- [x] Buy Eggs.
- [ ] Buy Milk.
- [ ] Wash Clothes.
  Buy Eggs

  Buy Milk
 

  Buy Books

 


Discussion

No Comment Found