HTML Lists Tutorial

HTML lists are used to organize and structure content on web pages.

There are three main types: unordered lists, ordered lists, and definition lists.

Unordered Lists (UL)

  1. Unordered lists are used for items that don't have a particular order or sequence.
  2. They are typically displayed with bullet points.
<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>  

<ul>: The unordered list element.

<li>: The list item element. Each list item is enclosed in

  • tags.

    • Item 1
    • Item 2
    • Item 3

    Ordered Lists (OL)

    1. Ordered lists are used for items that have a specific order or sequence.
    2. They are displayed with numbers, letters, or other sequential markers.
    <ol>
        <li>First Item</li>
        <li>Second Item</li>
        <li>Third Item</li>
    </ol>
    

    <ol>: The ordered list element.

    <li>: The list item element, as with unordered lists.

    1. First Item
    2. Second Item
    3. Third Item

    Definition Lists (DL)

    1. Definition lists are used for glossaries, dictionaries, or items with term-definition pairs.
    <dl>
        <dt>Term 1</dt>
        <dd>Definition 1</dd>
        <dt>Term 2</dt>
        <dd>Definition 2</dd>
    </dl>  
    

    <dl>: The definition list element.

    <dt>: The definition term element.

    <dd>: The definition description element.

    Term 1
    Definition 1
    Term 2
    Definition 2

    Nested Lists

    1. You can nest lists inside other lists to create hierarchical structures.
    <ul>
        <li>Item 1
          <ul>
            <li>Subitem 1</li>
            <li>Subitem 2</li>
          </ul>
        </li>
        <li>Item 2</li>
    </ul>
    
    • Item 1
      • Subitem 1
      • Subitem 2
    • Item 2

    List Styles

    You can use CSS to style lists, including changing the marker style, indentation, and spacing.

    Unordered List Styles

    1. list-style: disc; (default)
    2. list-style: circle;
    3. list-style: square;

    Ordered List Styles

    1. list-style: decimal; (default)
    2. list-style: lower-alpha;
    3. list-style: upper-roman;

    Definition List Styles

    1. list-style: none; (removes the bullets or numbers in a list)
    2. list-style: inherit; (inherits the list style from the parent element)
    <style>
        ul {
          list-style-type: square; /* Change the bullet style */
        }
        ol {
          list-style-type: upper-roman; /* Change the marker style */
        }
        li {
          margin: 10px 0; /* Adjust spacing between list items */
        }
    </style>