HTML ul

Definition of an Unordered List

An unordered list presents a set of related items without emphasizing their order. In HTML, it is created using the <ul> tag, with each item enclosed in <li> tags. These items appear as bulleted points by default.

Purpose of Using Unordered Lists in HTML

Unordered lists help organize and display information clearly, grouping related items without suggesting any specific order. They enhance readability and are ideal for menus, steps, options, and similar information.

Creating Unordered Lists

To create an unordered list in HTML:

  1. Open the HTML document.
  2. Insert the <ul> element where you want the list.
  3. 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 list markers using CSS. For example, to change the bullet style to a square and the bullet color to red:

Example:

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

Syntax for Creating an Unordered List in HTML

To create an unordered list, use the following syntax:

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

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

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

To add items to an unordered list:

  1. Identify the section for the list.
  2. Open the unordered list element <ul>.
  3. Insert each list item using the <li> element.
  4. Close the unordered list element with </ul>.

Example:

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

Nesting List Items Within an Unordered List

To create subcategories within a list, you can nest lists:

Example:

<ul>
  <li>Main item
    <ul>
      <li>Sub item 1</li>
      <li>Sub item 2</li>
    </ul>
  </li>
  <li>Another main item</li>
</ul>

This creates a hierarchical structure of list items.

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 follow a sequence, such as steps in a process.
  • Description Lists (<dl>): For terms and their descriptions.

Understanding Different Types of Lists

  • Unordered Lists (<ul>): Use bullet points for 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 various 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, 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 change bullet styles, use the list-style-type property in the <ul> tag:

Example:

ul {
  list-style-type: square;
}

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