Lists are used to group together related pieces of information so they are clearly associated with each other and easy to read. In modern web development, lists are workhorse elements, frequently used for navigation as well as general content.
Lists are good from a structural point of view as they help create a well-structured, more accessible, easy-to-maintain document. They are also useful because they provide specialized elements to which you can attach CSS styles. Finally, semantically correct lists help visitors read your web site, and they simplify maintenance when your pages need to be updated.
In HTML, there are three different types of list in HTML and each one has a specific purpose and meaning.
- Unordered list — Used to create a list of related items, in no particular order.
- Ordered list — Used to create a list of related items, in a specific order.
- Description list — Used to create a list of terms and their descriptions.
HTML Unordered Lists
An unordered list is a collection of related items that have no special order or sequence. This list is created by using HTML <ul> tag, and each list item starts with the <li>
element. The list items in unordered lists are marked with bullets. Here's an example:
Example
You can also change the bullet type in your unordered list using the CSS list-style-type
property. The following style rule changes the type of bullet from the default disc to square:
ul {
list-style-type: square;}
Types of Bullet Points
Disc (default)
Code: <ul style='list-style-type:disc'>
Circle
Code: <ul style='list-style-type:circle'>
Square
Code: <ul style='list-style-type:square'>
No Bullets
Code: <ul style='list-style-type:none'>
HTML Ordered Lists
An ordered list created using the <ol>
element, and each list item starts with the <li>
element. Ordered lists are used when the order of the list's items is important.
The list items in an ordered list are marked with numbers. Here's an example:
Example
Output
The numbering of items in an ordered list typically starts with 1. However, if you want to change that you can use the start
attribute, as shown in the following example:
Example
<ol start="10"><li>Mix ingredients</li><li>Bake in oven for an hour</li><li>Allow to stand for ten minutes</li></ol>
Output
Like unordered list, you can also use the CSS list-style-type
property to change the numbering type in an ordered list. The following style rule changes the marker type to roman numbers.
ol {list-style-type: upper-roman;}
The type Attribute
You can use type attribute for <ol> tag to specify the type of numbering you like. By default, it is a number. Following are the possible options
HTML Description Lists
A description list is a list of items with a description or definition of each item.
The description list is created using <dl>
element. The <dl>
element is used in conjunction with the <dt>
element which specify a term, and the <dd>
element which specify the term's definition.
Browsers usually render the definition lists by placing the terms and definitions in separate lines, where the term's definitions are slightly indented. Here's an example:
Example
Output
Styling Lists with CSS
CSS provides
the several properties for styling and formatting the most commonly used
unordered and ordered lists. These CSS list properties typically allow you to:
- Control the shape or appearance of the marker.
- Specify an image for the marker rather than a bullet point or number.
- Set the distance between a marker and the text in the list.
- Specify whether the marker would appear inside or outside of the box containing the list items.
In the
following section, we will discuss the properties that can be used to style HTML
lists.
Changing the Position of List Markers
By default,
markers of each list items are positioned outside
of
their display boxes.
However, you
can also position these markers or bullet points inside of the list item's
display boxes using the list-style-position
property along with the value inside
. In this case the lines will wrap under the marker instead of
being indented. Here's an example:
Example
Let's take a look at the following illustration to understand how markers or bullets are positioned.
Using Images as List Markers
You can also
set an image as a list marker using the list-style-image
property.
The style rule
in the following example assigns a transparent PNG image "arrow.png"
as the list marker for all the items in the unordered list. Let's try it out
and see how it works:
Example
See the Pen list-style-type examples by PANKAJ (@pankkap) on CodePen.
Remove Indentation
COLORED BULLETS in HTML using CSS
That's it.
If you have trouble typing those bullets into your style sheets, you can also use their Unicode numbers: • = "\2022", ◦ = \25E6" and ▪ = "\25AA"
Reference: Some Unique Unicode Characters
COLORED LIST NUMBERS
And then we use it like we did the bullet above: