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.
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>
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.
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>
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.
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>
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.
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>
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.
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.