HTML Lists
Explore ways to organize content in a logical and hierarchical manner on your web pages with HTML lists
Lists play a fundamental role in organizing and structuring information on webpages, offering a clear and concise way to present content. Whether you're creating a bullet-pointed list, a numbered sequence, or a hierarchical outline, understanding the various types of HTML lists is essential for effective communication.
In this lesson, we embark on a journey into the realm of HTML lists, exploring their versatility and practical applications. Gain insights into when and why to choose each type of list, from unordered lists that employ bullet points for items with no specific order, to ordered lists that bring a sense of sequence and hierarchy. Discover how to leverage nested lists to create subcategories and sub-items, enabling you to organize information in a hierarchical structure.
Use the <ul>
tag to create an unordered list. This type of list is great when the order of items is of no importance — for example, in shopping lists. Browsers usually mark the items in this type of list with bullet points. To list items, you use <li>
tags inside the <ul>
element.
Create ordered lists using the <ol>
tag. Items of ordered lists are numbered, and this type of list is the best option when the order of items is important — for example, in step-by-step instructions. Just like in unordered lists, you need to use <li>
Definition lists, also known as description lists, are introduced with the <dl>
The definition list element <dl>
hosts two types of items:
• Terms, introduced with the <dt>
tag
• Descriptions, introduced with the <dd>
tag[2]
Browsers usually render definition lists by placing the terms and definitions in separate lines, with definitions slightly indented.
A list's items can contain any type of
The trick to marking nested lists correctly is to recognize that the sublist is actually a child of a list item and not a list. Start by creating a list with <ul>
or <ol>
tag, add items with <li>
As we mentioned, browsers use round bullet points for unordered lists by default. However, you can set a custom bullet type using the CSS list-style-type property. Either add "list-style-type:square;"
to the <ul>
element through the style
attribute, or create a CSS rule for inside the <style>
ul {list-style-type: square;}
.
There are various ways to put items in an order. You can use Arabic numerals (1,2,3) for trivial things, Roman numbers (I, II, III) on classier occasions, or letters (A, B, C) when talking about backup plans. type
attribute.
Available values are:
• "1"
for Arabic numerals (default)
• "I"
for uppercase Roman numbers
• "i"
for lowercase Roman numbers
• "A"
for uppercase letters
• "a"
for lowercase letters
The specified type is used for the entire list unless a different type
attribute is used on an enclosed <li>
element.
The numbering of items in an ordered list typically starts with 1, but you can change this by adding the start attribute to the <ol>
<ol start="10">
will make your numbered list begin with the number 10.
Always use an Arabic numeral (1, 2, 3, etc.) for the start value, even when the numbering type is letters or Roman numerals. For example, to start numbering elements from the letter "d" or the Roman numeral "IV," use start="4"
.
Let's say you want to rate all Tom Hanks movies from worst to best (for whatever reason). It makes sense to start your list with the highest number and save number 1 for last, right? The good news is that
Add the reversed
attribute to the <ol>
Use the <li>
<ul>
and <ol>
tag.
The <ol>
type
attribute. Other attributes that this element can take includes start
(that defines the first item of the order) and reversed
(an attribute without value that reverses the order of items).
Browsers mark unordered lists with bullets by default. However, you can change the marker style by adding the list-style-type
You can set custom numbering of your ordered list with the type
attribute of the <ol>
A
for uppercase letters, a
for lowercase letters, i
for lowercase Roman numerals, I
for uppercase Roman numerals, and 1
for numbers (which is the default).