HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Lists

HTML lists are used to display information in a structured and organized manner. Lists are an important part of web design and are used to present information in a clear and concise way. There are three types of lists in HTML: ordered lists, unordered lists, and definition lists.

Ordered Lists

An ordered list is a list of items that are numbered in a specific order. The HTML code for an ordered list is:

<ol>
  <li>Item 1</li>
  <li>Item 2</li>
  <li>Item 3</li>
</ol>
  1. Item 1
  2. Item 2
  3. Item 3

The <ol> tag is used to create an ordered list. Each item in the list is created using the <li> tag. The items are automatically numbered in the order they appear in the list.

Unordered Lists

An unordered list is a list of items that are not numbered. The HTML code for an unordered list is:

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

The <ul> tag is used to create an unordered list. Each item in the list is created using the <li> tag. The items are displayed with bullet points by default, but this can be changed using CSS.

Definition Lists

A definition list is a list of terms and their definitions. The HTML code for a definition list is:

<dl>
  <dt>Term 1</dt>
  <dd>Definition 1</dd>
  <dt>Term 2</dt>
  <dd>Definition 2</dd>
  <dt>Term 3</dt>
  <dd>Definition 3</dd>
</dl>
Term 1
Definition 1
Term 2
Definition 2
Term 3
Definition 3

The <dl> tag is used to create a definition list. Each term in the list is created using the <dt> tag, and each definition is created using the <dd> tag.

Nested Lists

Lists can be nested inside other lists to create a more complex structure. For example, an ordered list can contain an unordered list, or a definition list can contain an ordered list. The HTML code for a nested list is:

<ol>
  <li>Item 1</li>
  <li>Item 2
    <ul>
      <li>Sub-item 1</li>
      <li>Sub-item 2</li>
    </ul>
  </li>
  <li>Item 3</li>
</ol>
  1. Item 1
  2. Item 2
    • Sub-item 1
    • Sub-item 2
  3. Item 3

In this example, an ordered list contains an unordered list as a sub-item. The sub-items are indented to show that they are part of the parent item.

Conclusion

HTML lists are an important part of web design and are used to present information in a clear and concise way. There are three types of lists in HTML: ordered lists, unordered lists, and definition lists. Lists can also be nested inside other lists to create a more complex structure.

References

Activity