HTML ul

Definition of an Unordered List

An unordered list is a way to present a set of related items without emphasizing their order. In HTML, it is created using the <ul> tag, and each item within the list is enclosed in <li> tags. These items appear as bulleted points by default, making them easily recognizable.

Purpose of Using Unordered Lists in HTML

Unordered lists help in organizing and displaying information clearly. They group related items without implying any specific order, enhancing readability. This format is ideal for menus, steps, options, and other related information.

Creating Unordered Lists

To create an unordered list in HTML:

  • Open the HTML document.
  • Insert the <ul> element where you want the list.
  • Add list items using the <li> element.
  • Example:

    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
    

    By default, these items will be displayed with bullet points.

    Customizing Unordered Lists with CSS

    You can change the appearance of the list item markers using CSS. For example, to change the bullet color:

    ul {
      list-style-type: square;
      color: red;
    }
    

    This code changes the bullet style to a square and the bullet color to red.

    Syntax for Creating an Unordered List in HTML

    To create an unordered list, use the following syntax:

    <ul>
      <li>Apple</li>
      <li>Orange</li>
      <li>Banana</li>
    </ul>
    

    The <ul> tag acts as the container, and the <li> tags represent each list item.

    Adding List Items to an Unordered List Using <li> Elements

    To add items to an unordered list, follow these steps:

  • Identify the section for the list.
  • Open the unordered list element <ul>.
  • Insert each list item using the <li> element.
  • Close the unordered list element with </ul>.
  • Example:

    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
    </ul>
    

    Nesting List Items Within an Unordered List

    You can create subcategories by nesting lists within another list:

    <ul>
      <li>Fruit
        <ul>
          <li>Apple</li>
          <li>Banana</li>
        </ul>
      </li>
      <li>Vegetables
        <ul>
          <li>Carrot</li>
          <li>Broccoli</li>
        </ul>
      </li>
    </ul>
    

    This nesting helps in creating a hierarchical structure.

    Types of Lists in HTML

    HTML provides three main types of lists:

  • Unordered Lists (<ul>): For items without a specific order.
  • Ordered Lists (<ol>): For items that need to be in a specific order, like steps in a process.
  • Description Lists (<dl>): For terms and their descriptions.
  • Understanding Different Types of Lists

    • Unordered Lists (<ul>): Use bullet points to display items.
    • Ordered Lists (<ol>): Use numbers or letters to display items in a sequence.
    • Description Lists (<dl>): Use <dt> for terms and <dd> for descriptions.

    CSS Properties for Styling Lists

    CSS offers several properties to style lists, including:

    • list-style-type: Changes the bullet style (e.g., disc, circle, square).
    • list-style-image: Uses an image as the bullet.
    • background-color: Sets the background color for the list or items.
    • padding, margin, font-size, and color: Customize spacing, size, and color.

    Introduction to the list-style-type Property in CSS

    The list-style-type property customizes the bullet type for list items. Common values include:

    • disc: Default filled circle.
    • circle: Hollow circle.
    • square: Filled square.
    • none: No marker.

    Example:

    ul {
      list-style-type: circle;
    }
    

    Customizing Bullet Styles for Unordered Lists

    To customize bullet styles, use the list-style-type property in the <ul> tag:

    <ul style="list-style-type: square;">
      <li>First item</li>
      <li>Second item</li>
      <li>Third item</li>
    </ul>
    

    This example changes the default bullet to a square.

    Create a free account to access the full topic

    “It has all the necessary theory, lots of practice, and projects of different levels. I haven't skipped any of the 3000+ coding exercises.”
    Andrei Maftei
    Hyperskill Graduate