Table of contents
1.
Introduction
2.
Definition and Usage  
2.1.
Ordered Lists (`<ol>`)  
2.2.
Unordered Lists (`<ul>`)  
2.3.
Key Points to Remember
3.
Syntax of <li> Tag
3.1.
Explanation:
4.
Attributes of <li> Tag
4.1.
Type Attribute
4.1.1.
Example of Type Attribute in Unordered List
4.2.
Value Attribute
4.2.1.
Example of Value Attribute in Ordered List:
5.
Examples of <li> Tag in Action
5.1.
Unordered List Example
5.2.
Ordered List Example
5.3.
Nested List Example
6.
Frequently Asked Questions
6.1.
Can I use the <li> tag without <ul> or <ol>?
6.2.
What is the default type for an unordered list using <li>?
6.3.
Can I use CSS to style the <li> tag?
7.
Conclusion
Last Updated: Jan 5, 2025
Easy

<li> Tag in HTML

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

The <li> tag in HTML is used to define a list item within ordered, unordered, or menu lists. It plays an essential role in structuring content, especially when creating lists for menus, navigation bars, or any grouped information. Each <li> element represents a single item in the list, and its appearance depends on whether it belongs to an ordered list (<ol>), an unordered list (<ul>), or a menu list (<menu>).

<li> Tag in HTML

In this article, you will learn about the <li> tag, its syntax, attributes, and how to use it effectively in HTML to create well-structured and readable lists for your web projects.

Definition and Usage  

The `<li>` tag in HTML is used to define a list item. It is always nested inside either an ordered list (`<ol>`) or an unordered list (`<ul>`). The `<li>` tag itself doesn’t do much on its own, but when combined with `<ol>` or `<ul>`, it becomes a powerful tool for organizing content.  

Ordered Lists (`<ol>`)  

An ordered list is used when the sequence of items matters. For example, if you’re writing steps for a recipe or ranking items, you’d use an ordered list. Each `<li>` inside an `<ol>` is automatically numbered by the browser.  

Unordered Lists (`<ul>`)  

An unordered list is used when the order of items doesn’t matter. For example, a shopping list or a list of features in a product. Each `<li>` inside a `<ul>` is displayed with a bullet point by default.  

Key Points to Remember

1. The `<li>` tag must be placed inside `<ol>` or `<ul>`.  
 

2. You can add text, images, links, or even other HTML elements inside an `<li>`.  
 

3. The `<li>` tag supports global attributes like `class`, `id`, & `style`.  

Syntax of <li> Tag

The <li> tag is used within list elements like <ul> (unordered list) or <ol> (ordered list). Its basic syntax is:

<ul>
  <li>Item 1</li>
  <li>Item 2</li>
</ul>


Explanation:

  • The <ul> or <ol> tags define the type of list (unordered or ordered).
     
  • Each <li> tag represents a list item.
     
  • The text between the opening <li> and closing </li> represents the content of that list item.

Attributes of <li> Tag

The <li> tag has specific attributes that control its behavior or appearance. 

Type Attribute

The type attribute specifies the style of bullet or number for the list item. It can be used with the <ol> or <ul> parent tags. The common values are:

  • disc (default for unordered lists)
     
  • circle
     
  • square

For ordered lists:

  • 1 (default: numbers)
     
  • A (uppercase letters)
     
  • a (lowercase letters)
     
  • I (uppercase Roman numerals)
     
  • i (lowercase Roman numerals)

Example of Type Attribute in Unordered List

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Unordered List Example</title>
</head>
<body>
    <h1>Unordered List with Circle Bullets</h1>
    <ul type="circle">
        <li>HTML</li>
        <li>CSS</li>
        <li>JavaScript</li>
    </ul>
</body>
</html>


Output:

Output

Value Attribute

The value attribute sets a custom number or position for a specific list item in an ordered list.

Example of Value Attribute in Ordered List:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ordered List Example</title>
</head>
<body>
    <h1>Ordered List with Custom Starting Number</h1>
    <ol>
        <li>Item 1</li>
        <li value="10">Item 10</li>
        <li>Item 11</li>
    </ol>
</body>
</html>


Output:
 

Output

Examples of <li> Tag in Action

Here are some practical examples to help you understand how to use the <li> tag effectively.

Unordered List Example

Unordered lists are great for bullet points or listing items without a specific sequence.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Unordered List Example</title>
</head>
<body>
    <h1>Fruits List</h1>
    <ul>
        <li>Apple</li>
        <li>Banana</li>
        <li>Cherry</li>
    </ul>
</body>
</html>


Output:

Output

Ordered List Example

Ordered lists are ideal for steps or tasks where sequence matters.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ordered List Example</title>
</head>
<body>
    <h1>Steps to Get Started</h1>
    <ol>
        <li>Sign up</li>
        <li>Verify your email</li>
        <li>Start learning</li>
    </ol>
</body>
</html>


Output:

Output

Nested List Example

Nested lists are used to create subcategories within a list.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nested Unordered List Example</title>
</head>
<body>
    <h1>Topics</h1>
    <ul>
        <li>Programming Languages
            <ul>
                <li>Python</li>
                <li>Java</li>
                <li>C++</li>
            </ul>
        </li>
        <li>Web Development Tools
            <ul>
                <li>HTML</li>
                <li>CSS</li>
                <li>JavaScript</li>
            </ul>
        </li>
    </ul>
</body>
</html>


Output:

Output

Frequently Asked Questions

Can I use the <li> tag without <ul> or <ol>?

No, the <li> tag must always be nested inside <ul> or <ol> elements to define the context of the list.

What is the default type for an unordered list using <li>?

The default type is disc, which displays bullet points.

Can I use CSS to style the <li> tag?

Yes, CSS can be used to customize the appearance of list items, including their bullet style, font, color, and more.

Conclusion

The <li> tag is a fundamental part of HTML, enabling developers to create lists that enhance the structure and readability of web pages. Whether it's a simple grocery list or a complex nested list, the <li> tag is versatile and easy to use. By mastering its attributes like type and value, you can add both functionality and style to your lists.

You can also check out our other blogs on Code360.

Live masterclass