Why do we need to declare the <ul> & <ol> tags in HTML ?
Last Updated :
01 Feb, 2022
The <ul> tag is used to create an unordered list. It is used to make a list in those situations where the ordering of list items is not significant. On the other hand, the <ol> tag is to create an ordered list. As the name implies, it is used in those situations where list items are maintained order-wise. Every list has one or more list elements which are represented using the <li> tag.
In this article, we will learn about the usage of both <ul> and <ol> tags while creating the list in the HTML document.
HTML Unordered List: The <ul> tag is used to create an unordered/bulleted list in the HTML document. It is used to group items of particular information where the order is not important like the menu card of a restaurant, features of a product, etc.
The <ul> tag is paired tag so it must have starting <ul> and closing</ul> tags. The list elements are marked using <li> tag which is empty/unpaired tag i.e., closing </li> tag is optional. These are block elements, so the line break is automatically inserted below and above the tags.
Syntax:
<ul type="disc">
<li> List element1 </li>
<li> List element2 </li>
...
</ul>
Attribute Values:
- disc: solid disc appears before the list element
- circle: empty circle appears before the list element
- square: solid square appears before the list element
- none: noting will appear
Note: If you have not specified any type attribute then by default, a solid disc appears before the list elements.
Example 1: This is a simple example that will illustrate the list in an unordered form.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Unordered List</title>
</head>
<body>
<h2>Unordered List</h2>
<ul type="circle">
<li>Computers</li>
<li>Science</li>
<li>Mathematics</li>
<li>Languages</li>
<li>Social Sciences</li>
</ul>
</body>
</html>
Output:
Example 2: This example will illustrate the use of a nested form of an unordered list.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Nested Unordered List</title>
</head>
<body>
<h2>Nested Unordered List</h2>
<ul type="circle">
<li>Programming Languages
<ul type="square">
<li>C++</li>
<li>Python</li>
</ul>
<li>Softwares</li>
<ul type="square">
<li>System Software</li>
<li>Application Software</li>
</ul>
</ul>
</body>
</html>
Output:
HTML Ordered List: The <ol> is used to create an ordered/numbered list in the HTML document. It is used to group items of information in a specific order like instructions to install application software etc.
The <ol> tag is paired tag so it must have starting <ol> and closing</ol> tags. The list elements are marked using <li> tag which is empty/unpaired tag i.e., closing </li> tag is optional. These are block elements, so the line break is automatically inserted below and above the tags.
Syntax:
<ol type="1">
<li> List element1 </li>
<li> List element2 </li>
...
</ol>
Attribute Values:
- number: Numbers will appear before the list element ex: 1, 2, 3.
- lowercase letters: Lowercase Letters will appear before the list element ex: a, b, c.
- Uppercase letters: Uppercase Letters will appear before the list element ex: A, B, C.
- Lowercase Roman: Lowercase Roman will appear before the list element ex: i, ii, iii.
- Uppercase Roman: Uppercase Roman will appear before the list element ex: I, II, III.
Note: If you have not specified any type attribute then by default, Numbers will appear before the list elements specified with <li> tag when the webpage is viewed in a web browser.
Example 1: This is a simple example that will illustrate the list in an ordered form.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Ordered List</title>
</head>
<body>
<h2>Ordered List</h2>
<ol type="1" start="2">
<li type="a"> Desktop
<li type="A" value="6">Laptop
<li type="i">Tablet
<li type="I">Mobile Phone
</ol>
</body>
</html>
Output:
Example 2: This example will illustrate the use of a nested form of an ordered list.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Nested Ordered List</title>
</head>
<body>
<h2>Nested Ordered List</h2>
<ol>
<li> Programming Languages
<ol type="A">
<li>Python
<li>R
</ol>
<li> Softwares
<ol type="I">
<li>System Software
<li>Application Software
</ol>
</ol>
</body>
</html>
Output:
We can also use both ordered and unordered lists at the same list and create a nested list.
Example:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Nested Ordered and Unordered List</title>
</head>
<body>
<h2>Nested Ordered and Unordered List</h2>
<ol>
<li> Programming Languages
<ol type="i">
<li>Python
<li>R
</ol>
<li> Softwares
<ul type="square">
<li>System Software
<li>Application Software
</ul>
</ol>
</body>
</html>
Output:
Similar Reads
How to implement various types of lists in HTML ? HTML lists are used to display items in an organized format. There are three types: unordered lists(<ul>), which use bullets; ordered lists (<ol>), which use numbers; and definition lists (<dl>), which pair terms with descriptions. Each type serves specific purposes.HTML lists allo
4 min read
What is nesting of list & how to create the nested list in HTML ? Nesting of lists in HTML involves placing one list within another list item, creating a hierarchical structure. This is done by embedding a <ul> (unordered) or <ol> (ordered) list inside an <li> (list item) element. The proper way to make a nested HTML list is to use the <ul>
3 min read
Unordered, Ordered, and Description Lists in HTML Lists are used to store data or information in web pages in ordered or unordered form. HTML supports several types of list elements that can be included in the <BODY>tag of the document. These elements may also be nested, i.e., the onset of elements can be embedded within another. There are th
5 min read
How to Create an Unordered List in HTML ? An unordered list in HTML is a collection of items displayed with bullet points. To create an unordered list, we can use the <ul> tag to start the list and <li> tags for each items. Unordered lists are usually displayed with bullet points. Syntax<ul> <li>apple</li> <
1 min read
How to create a nested webpage in HTML ? When the content of one completely different webpage is embedded into another webpage, it is called a nested webpage. In simple words, a webpage that is inside another webpage of a completely different domain. In this article, we are going to learn how to create a nested webpage. There are two metho
2 min read
How to define a list item in HTML5? To define a list in HTML5 we can use the HTML <li> tag. But there are two types of listing in HTML. One is an ordered list and another one is an unordered list. For ordered we can use HTML <ol> tag and for the unordered list, we will use the HTML <ul> tag. Also, we can change the l
2 min read
How to set list in descending order in HTML5 ? HTML Lists are used to create informative lists. Any list will have one or more list items. We have three types of lists in HTML. ul: An unordered list is referred to as an ul. Simple bullets would be used to list the items.ol: A number that is arranged in a certain order. This will list the items u
2 min read
How to create a list with roman number indexing in HTML ? Roman numeral indexing in HTML lists employs Roman numerals (I, II, III, etc.) for item markers. This can be achieved by specifying the type attribute of the <ol> tag as "I", "i", "A", "a", "I", or "i", or by manually numbering list items with Roman numerals. This guide provides all approaches
2 min read
How to specify the kind of marker to be used in the list in HTML5 ? There are two types of lists in HTML, the first is an ordered list which is created using the <ol></ol> tag, and the second is an unordered list which is created using the <ul></ul> tag. Both of the lists should have a <li></li> tag to represent the data inside th
3 min read
What is the way to keep list of elements straight in HTML file ? In this article, we will discuss various methods to keep the list of elements straight in an HTML file. Generally, The proper indented content in the browser makes the content well-organized & structured, enhancing the overall readability, along with increasing the interactivity of the website.
6 min read