Javatpoint Logo
Javatpoint Logo

UL Tag in HTML

UL Tag

The <ul> tag, which stands for "unordered list," is a crucial HTML component used to generate lists of items where the order of the items has no significance.

Unordered lists (<ul>) are used when the order of the items is not important, and you wish to present the elements with bullet points or other markers to denote separation, in contrast to ordered lists (<ol>), which depict lists with a defined 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:

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

Here is a simple example of how to use the HTML <ul> tag to create an unordered list:

This example creates an unordered list with bullet points by enclosing three list items (<li>) in <ul> tags as follows:

UL Tag in HTML

Attributes of the UL Tag

Several attributes are supported by the HTML <ul> tag and can be used to modify the appearance and behaviour of unordered lists. Here are some typical attributes and their outcomes:

1. Type Attribute:

The type attribute describes the bullet point or marker used for list items.

The common values "disc" (the default filled circle), "circle" (the empty circle), and "square" (the filled square) are all examples.

Example: This example uses the type attribute with different values.

Output:

UL Tag in HTML

2. Class Attribute

The class attribute enables you to provide the <ul> element with a CSS class that may be used to style or target the list with CSS.

Example:

Output:

UL Tag in HTML

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 demonstrate nested unordered lists, let's create a simple example. Consider making a list of animals with sub-lists for each animal category:

Example:

Output:

UL Tag in HTML

Styling Unordered Lists

You may style unordered lists using CSS (Cascading Style Sheets) to make them look the way you want them to on your website. You can change many features, such as text attributes, list markers (bullets), and the distance between items. Here's how to use CSS to style unordered lists:

1. Changing List Markers (bullets):

The list-style-type parameter allows you to modify how list markers appear. Disc (the default filled circle), circle (the empty circle), square (the filled square), and custom images are examples of common values.

2. Customizing List Markers Position:

To change the position of list markers, use the list-style-position property. When set inside, markers are placed inside the list item's content-box; when set to outside (the default), they are outside.

3. Modifying Text Properties

Targeting the <li> elements within the <ul> will allow you to change the text properties within list items, such as color, font, and size.

4. Spacing

Using the margin or padding properties, change the spacing between list items. To add space between list items, for instance:

5. Custom Images as List Markers

By including the URL of your custom image in the list-style-image attribute, you may use it as a list marker.

The complete example of CSS code for styling an unordered list is shown below:

Output:

UL Tag in HTML

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:

  1. 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.
  2. 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.
  3. 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.
  4. Links: Unordered lists can be used to build lists of similar connections, such as social networking links, resource links, or links to relevant articles.
  5. 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

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<ul>YesYesYesYesYes






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA