UL Tag in HTML

UL Tag

The <ul> tag, known as the "ul" tag, is an essential HTML element utilized to create lists of items without any specific order.

Unordered lists (<ul>) serve the purpose of displaying items without a specific sequence, using bullets or other symbols to indicate individual elements, as opposed to ordered lists (<ol>), which organize content in a specific numerical or alphabetical order.

Purpose:

  • The <ul> tag's primary objective is to structure and arrange content non-sequentially.
  • It is frequently used to create content that doesn't require a rigid sequence, such as lists of items and navigation menus. List items (<li>) are used within an <ul> element to define each item within the list.
  • By default, list items are presented as bullet points; however, this can be changed using CSS.
  • Basic Syntax and Structure

Syntax:

Example

<ul>
    <!-- List items go here -->
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>

Unordered lists combine the <ul> tag with< li> elements. One item in the list is represented by each <li> element.

Here is a basic illustration of employing the HTML <ul> tag to generate an unordered list:

Example

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

This illustration generates an unnumbered list with bullet points by surrounding three list items (<li>) with <ul> tags like this:

Attributes of the UL Tag

Several properties are provided by the HTML <ul> element, enabling customization of unordered lists' appearance and functionality. Below are common attributes along with their effects:

1. Type Attribute:

The type attribute specifies the bullet point or marker that is applied to list items.

The standard options "disc" (representing a solid circle by default), "circle" (indicating an empty circle), and "square" (depicting a solid square) are all instances.

Example: This instance demonstrates the utilization of the type attribute with varying settings.

Example

<!Doctype Html>  
<Html>     
<Head>      
<Title>     
Ul tag with a Type attribute  
</Title>  
</Head>  
<Body>   
Hello User!.... <br>  
The following list uses the Square mark in front of the list items.   
<ul type="square">  
<li> Cars </li>  
<li> bikes </li>  
<li> Aeroplanes </li>  
<li> Trains </li>  
<li> Ships </li>  
</ul>  
The following list uses the Circle mark in front of list items.   
<ul type="Circle">  
<li> BMW </li>  
<li> Audi </li>  
<li> Mercedes </li>  
<li> Jaguar </li>  
<li> Lamborghini </li>  
</ul>  
The following list uses the Disc mark in front of list items.   
<ul type="disc">  
<li> Apache </li>  
<li> KTM </li>  
<li> R15 </li>  
<li> Ducati </li>  
<li> Harley-Davidson </li>  
</ul>  
</Body>   
</Html>

Output:

2. Class Attribute

The class attribute allows you to assign a CSS class to the <ul> element, which can then be utilized for styling or targeting the list using CSS.

Example:

Example

<html>
<head>
    <style>
        .custom-list{
            color:yellow;
            background-color:grey;
        }
    </style>
</head>
<body>
<ul class="custom-list">
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>
</body>
</html>

Output:

Creating Nested Unordered Lists in HTML

You may create hierarchical structures with nested unordered lists, where a sub-list is contained within an item of an outer list. A <ul> (unordered list) or <ol> (ordered list) element is inserted inside a <li> (list item) element to accomplish this. To build nested unordered lists, follow these steps:

  • To start working with the outer unordered list, open an outer <ul> element.
  • Open a second <ul> element inside a <li> element of the outer list to produce the inner unordered list.
  • To specify the things inside the inner <ul>, add <li> elements.
  • Example of Nested Unordered Lists:

To showcase nested bulleted lists, we will illustrate with a basic illustration. Imagine compiling a list of creatures with indented sub-lists for every animal type:

Example:

Example

<ul>
    <li>Mammals
        <ul>
            <li>Lion</li>
            <li>Elephant</li>
            <li>Monkey</li>
        </ul>
    </li>
    <li>Birds
        <ul>
            <li>Eagle</li>
            <li>Ostrich</li>
            <li>Parrot</li>
        </ul>
    </li>
    <li>Reptiles
        <ul>
            <li>Crocodile</li>
            <li>Snake</li>
            <li>Turtle</li>
        </ul>
    </li>
</ul>

Output:

Styling Unordered Lists

You have the ability to customize unordered lists through CSS (Cascading Style Sheets) to achieve the desired appearance on your website. Various elements like text properties, list markers (bullets), and spacing between items can be modified. Below are the steps to apply CSS for styling unordered lists:

1. Changing List Markers (bullets):

The list-style-type property enables customization of the appearance of list markers. Options such as disc (solid circle by default), circle (hollow circle), square (solid square), and user-defined images are typical choices.

Example

/* Set the list's marker to square.*/
ul {
    list-style-type: square;
}

2. Customizing List Markers Position:

To reposition list markers, utilize the list-style-position attribute. When designated as inside, markers are positioned within the content-box of the list item; whereas when set as outside (the default), they appear outside the box.

Example

/* Put list markers inside the items on the list. */
ul {
    list-style-position: inside;
}

3. Modifying Text Properties

Targeting the <li> elements inside the <ul> will enable you to modify the text characteristics within list items, like color, font, and size.

Example

/* Modifying font and text color.*/
ul li {
    color: #333;
    font-family: Arial, sans-serif;
}

4. Spacing

Adjust the gaps between list items by utilizing either the margin or padding properties. For example, to increase the space between list items:

Example

ul li {
    margin-bottom: 10px;
}

5. Custom Images as List Markers

By adding the web address of your personalized image to the list-style-image property, you can utilize it as a marker for your list items.

Example

/* As the list marker, using a custom image. */
ul {
    list-style-image: url('custom-marker.png');
}

Below is a full illustration of CSS code for styling an unordered list:

Example

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

li {
  margin-bottom: 5px;
  background-color: #f2f2f2;
  padding: 10px;
  border: 1px solid #ccc;
}
Example

<!DOCTYPE html>
<html>
<head>
    <title>Styled Unordered List</title>
    <style>
        /* Style*/
        ul {
            list-style-type: square; /* Change marker to squares */
            list-style-position: inside; /* Place markers inside list items */
            margin-left: 20px; /* Add margin to the left */
        }
        /* Style list items */
        ul li {
            margin-bottom: 10px; /* Add margin between list items */
            color: #333; /* Change text color */
            font-family: Arial, sans-serif; /* Change font family */
        }
    </style>
</head>
<body>
    <h2>Styled Unordered List</h2>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>
</body>

Output:

Practical Use Cases for Unordered Lists in Web Design:

Unordered lists (abbreviated as "ul" in web design) are flexible elements that may be used to improve how content is organized and presented on websites. Unordered lists are frequently used in the following situations from the real world:

  • Site Maps: Site maps or site index pages sometimes employ unordered lists to show the overall structure of a website. Users can more easily navigate and find particular material or sections.
  • Website navigation menus: Unordered lists are frequently used in website navigation menus. Links within list items enable navigation to various parts of the site, and each list item (li>) serves as a menu item.
  • Bullet Lists: Unordered lists are the best list to use when displaying content in a bulleted fashion. This is frequently used for websites' features, advantages, essential points, or FAQs.
  • Links: Unordered lists can be used to build lists of similar connections, such as social networking links, resource links, or links to relevant articles.
  • Content Organization: Unorganized lists help organize and arrange content on web pages. They can be used to group objects or information that are related.
  • Supporting Browsers

Element Chrome IE Firefox Opera Safari
<ul> Yes Yes Yes Yes Yes

Input Required

This code uses input(). Please provide values below: