HTML List

HTML can have Unordered Lists, Ordered Lists, or Description Lists:

Unordered  HTML List

  • The first item
  • The second item
  • The third item
  • The fourth item

Ordered HTML List

  1. The first item
  2. The second item
  3. The third item
  4. The fourth item

HTML Description List

The first item
Description of item
The second item
Description of item


Unordered HTML Lists

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
The list items will be marked with bullets (small black circles).

Unordered List:

<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>

Try it Yourself »


Unordered HTML Lists - The Style Attribute

style attribute can be added to an unordered list, to define the style of the marker:
StyleDescription
list-style-type:discThe list items will be marked with bullets (default)
list-style-type:circleThe list items will be marked with circles
list-style-type:squareThe list items will be marked with squares
list-style-type:noneThe list items will not be marked

Disc:

<ul style="list-style-type:disc">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ul>

Try it Yourself »

Circle:

<ul style="list-style-type:circle">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ul>

Try it Yourself »

Square:

<ul style="list-style-type:square">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ul>

Try it Yourself »

None:

<ul style="list-style-type:none">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ul>

Try it Yourself »

Note<ul type="xxx"> also works, but the type attribute of the <ul> tag is not valid in HTML5.

Ordered HTML Lists

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.
The list items will be marked with numbers.

Ordered List:

<ol>
  <li>Coffee</li>
  <li>Milk</li>
</ol>

Try it Yourself »


Ordered HTML Lists - The Type Attribute

type attribute can be added to an ordered list, to define the type of the marker:
TypeDescription
type="1"The list items will be numbered with numbers (default)
type="A"The list items will be numbered with uppercase letters
type="a"The list items will be numbered with lowercase letters
type="I"The list items will be numbered with uppercase roman numbers
type="i"The list items will be numbered with lowercase roman numbers

Numbers:

<ol type="1">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ol>

Try it Yourself »

Upper Case:

<ol type="A">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ol>

Try it Yourself »

Lower Case:

<ol type="a">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ol>

Try it Yourself »

Roman Upper Case:

<ol type="I">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ol>

Try it Yourself »

Roman Lower Case:

<ol type="i">
  <li>Coffee</li>
  <li>Tea
  <li>Milk</li>
</ol>

Try it Yourself »


HTML Description Lists

A description list, is a list of terms, with a description of each term.
The <dl> tag defines a description list.
The <dt> tag defines the term (name), and the <dd> tag defines the data (description).

Description List:

<dl>
  <dt>Coffee</dt>
  <dd>- black hot drink</dd>
  <dt>Milk</dt>
  <dd>- white cold drink</dd>
</dl>

Try it Yourself »


Nested HTML Lists

List can be nested (lists inside lists).

Nested Lists:

<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  </li>
  <li>Milk</li>
</ul>

Try it Yourself »
NoteList items can contain new list, and other HTML elements, like images and links, etc.

Horizontal Lists

HTML lists can be styled in many different ways with CSS.
One popular way, is to style a list to display horizontally:

Horizontal List:

<!DOCTYPE html>
<html>

<head>
<style>
ul.menu li {
    display:inline;
}
</style>
</head>

<body>

<h2>Horizontal List</h2>

<ul class="menu">
  <li>Apples</li>
  <li>Bananas</li>
  <li>Lemons</li>
  <li>Oranges</li>
</ul>

</body>
</html>

Try it Yourself »

Share this

Related Posts

Previous
Next Post »