HTML Lists

HTML lists group related items together. There are three types: unordered lists (bullets), ordered lists (numbers) and description lists (terms with meanings).


Unordered list (ul)

Use <ul> for a list where the order does not matter. Each item is in an <li> tag.

<ul>
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>
Output in the browser
  • HTML
  • CSS
  • JavaScript


Ordered list (ol)

Use <ol> when the order is important, like steps.

<ol>
  <li>Open the editor</li>
  <li>Write the code</li>
  <li>Save the file</li>
</ol>
Output in the browser
  1. Open the editor
  2. Write the code
  3. Save the file

Attributes of ol

AttributeMeaningExample
typeNumber style: 1, A, a, I, i<ol type="A">
startStarting number<ol start="5">
reversedCount down<ol reversed>

Nested lists

A list can be placed inside a list item.

<ul>
  <li>Fruits
    <ul>
      <li>Apple</li>
      <li>Mango</li>
    </ul>
  </li>
  <li>Vegetables</li>
</ul>
Output in the browser
  • Fruits
    • Apple
    • Mango
  • Vegetables


Description list (dl)

A description list has terms (<dt>) and their descriptions (<dd>).

<dl>
  <dt>HTML</dt>
  <dd>Language for the structure of web pages</dd>
  <dt>CSS</dt>
  <dd>Language for the style of web pages</dd>
</dl>
Output in the browser
HTML
Language for the structure of web pages
CSS
Language for the style of web pages

Note: Menus on websites are also built with lists. A navigation menu is usually a <ul> inside a <nav>, styled with CSS. Read the interview question different tags to list items.

Summary

  • ul = bullets, ol = numbers, dl = terms and descriptions.
  • Every item of ul and ol goes in an li.
  • Lists can be nested.
  • Next: HTML Iframes.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.