Lesson 6 +10 XP

Lists

We love lists! Grocery lists, to-do lists, top-10 lists. HTML has three kinds.

Unordered list: <ul>

A bullet-point list. "Unordered" = the order doesn't matter.

Code

html
<ul>
  <li>Apples</li>
  <li>Bananas</li>
  <li>Cherries</li>
</ul>

Ordered list: &lt;ol&gt;

A numbered list. &quot;Ordered&quot; = the order matters.

Code

html
<ol>
  <li>Wake up</li>
  <li>Brush teeth</li>
  <li>Eat breakfast</li>
</ol>

List items: &lt;li&gt;

&lt;li&gt; is one item, and it always lives inside a list.

Start and reverse

  • start=&quot;3&quot;: begin counting from 3 instead of 1.
  • reversed: count backwards.
Code

html
<ol start="3">
  <li>Three</li>
  <li>Four</li>
</ol>

Description list: &lt;dl&gt;

A list of terms and their descriptions. Like a dictionary!

  • &lt;dl&gt;: the whole description list
  • &lt;dt&gt;: the term being described
  • &lt;dd&gt;: the description
Code

html
<dl>
  <dt>HTML</dt>
  <dd>The skeleton of web pages.</dd>
  <dt>CSS</dt>
  <dd>The paint of web pages.</dd>
</dl>

Menu: &lt;menu&gt;

&lt;menu&gt; is like &lt;ul&gt;, but for a group of commands or actions (like a toolbar).

Code

html
<menu>
  <li><button>Copy</button></li>
  <li><button>Paste</button></li>
</menu>

Nesting lists

You can put a list inside a list item to make sub-lists!

Code

html
<ul>
  <li>Fruit
    <ul>
      <li>Apples</li>
      <li>Oranges</li>
    </ul>
  </li>
  <li>Vegetables</li>
</ul>

TL;DR

  • &lt;ul&gt; = bullet list, &lt;ol&gt; = numbered list.
  • &lt;li&gt; = one item in a list.
  • &lt;dl&gt; = description list with &lt;dt&gt; (term) and &lt;dd&gt; (description).
  • &lt;menu&gt; = a list of actions.
  • Lists can be nested inside each other.