Unordered lists and ordered lists are commonly used in HTML:
Unordered List |
Ordered List |
The
first item
|
The
first 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):
Example :
<!DOCTYPE
html>
<html>
<body>
<h2>Unordered
List with
Default
Bullets</h2>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
|
Unordered List with Default Bullets
|
Unordered HTML Lists - The Style Attribute
A
style
attribute can be added to an unordered
list, to define the style of
the marker:
Style
|
Description
|
list-style-type:disc | The list items will be marked with bullets (default) |
list-style-type:circle | The list items will be marked with circles |
list-style-type:square | The list items will be marked with squares |
list-style-type:none | The list items will not be marked |
Disc Example:
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Disc Bullets</h2>
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>Unordered List with Disc Bullets
- Coffee
- Tea
- Milk
Circle Example:
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Circle Bullets</h2>
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>Unordered List with Circle Bullets
o Coffeeo Teao Milk
Square Example:
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List with Square Bullets</h2>
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>Unordered List with Square Bullets
None Example:
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List without Bullets</h2>
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>Unordered List without Bullets
CoffeeTeaMilk
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:
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List</h2>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>Ordered List
- Coffee
- Tea
- Milk
Ordered HTML Lists - The Type Attribute
A
type
attribute can be added to an ordered
list,
to define the type of the marker:
Type
|
Description
|
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 Example:
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Numbers</h2>
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>Ordered List with Numbers
- Coffee
- Tea
- Milk
Uppercase Letters Example:
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Letters</h2>
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>Ordered List with Letters
- Coffee
- Tea
- Milk
Lowercase Letters Example:
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Lowercase Letters</h2>
<ol type="a">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>Ordered List with Lowercase Letters
- Coffee
- Tea
- Milk
Uppercase Roman Numbers Example:
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Roman Numbers</h2>
<ol type="I">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>Ordered List with Roman Numbers
- Coffee
- Tea
- Milk
Lowercase Roman Numbers Example:
<!DOCTYPE html>
<html>
<body>
<h2>Ordered List with Lowercase Roman Numbers</h2>
<ol type="i">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>Ordered List with Lowercase Roman Numbers
- Coffee
- Tea
- Milk
HTML Description Lists
HTML
also supports description lists.
A
description list is a list of terms, with a description of each term.
The
<dl>
tag defines the description list, the <dt>
tag defines the term (name), and the <dd>
tag describes each term:
Example:
<!DOCTYPE html>
<html>
<body>
<h2>A Description List</h2>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</body>
</html>A Description List
- Coffee
- - black hot drink
- Milk
- - white cold drink
Nested HTML Lists
List
can be nested (lists inside lists):
Example
:
<!DOCTYPE html>
<html>
<body>
<h2>A Nested List</h2>
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</body>
</html>A Nested List
- Coffee
- Tea
- Black tea
- Green tea
- Milk
Summary
:
Use
the HTML <ul>
element to define an unordered list
- Use the HTML style attribute to define the bullet style
- Use the HTML <ol> element to define an ordered list
- Use the HTML type attribute to define the numbering type
- Use the HTML <li> element to define a list item
- Use the HTML <dl> element to define a description list
- Use the HTML <dt> element to define the description term
- Use the HTML <dd> element to define the description data
- Lists can be nested inside lists
- List items can contain other HTML elements