HTML Lists

HTML provides three types of lists: unordered, ordered, and definition lists. HTML Lists are essential for structuring content on web pages.

Unordered Lists

Use <ul> for unordered lists. Each list item is wrapped in <li>.

Example:

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

Ordered Lists

For ordered lists, employ <ol>. Similarly, wrap each item in <li>.

Example:

<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>

Nested Lists

You can nest lists inside other lists to create a hierarchy.

Example:

<ul>
  <li>Main item 1</li>
  <li>Main item 2
    <ul>
      <li>Subitem 1</li>
      <li>Subitem 2</li>
    </ul>
  </li>
  <li>Main item 3</li>
</ul>

Definition Lists

Definition lists are created using <dl>, <dt>, and <dd>.

Example:

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

Adding Attributes

Lists can have attributes for customization.

Example with a class:

<ul class="custom-list">
  <li>Item 1</li>
  <li>Item 2</li>
</ul>

Styling Lists with CSS

Enhance the visual appeal of your lists using CSS for styling.

Example:

.custom-list {
  color: #3498db;
  font-size: 16px;
}

Demo:

  • Item 1
  • Item 2

Accessibility Considerations

Ensure your lists are accessible by using semantic HTML and providing appropriate ARIA attributes.

Remember, practice is key to mastering HTML lists. Experiment with different types and styles to enhance your web design skills.