HTML UL Tag: Create Ordered & Unordered Lists -- Examples & Best Practices
The
- tag in HTML is an essential element for creating unordered lists. It's a container for items that are not in any specific order, and it's often used for lists of options, like navigation menus or general bullet-pointed lists. This tag is a useful tool for making your content more readable and engaging. Let's dive into some practical examples to understand its usage better.
- tag, which is used to define the list items. The
- tag can contain text or other HTML elements, creating flexible and dynamic lists.
Basic unordered list example
Here's a basic example of an unordered list using the
- and
- tags:
- Apples
- Bananas
- Cherries
As you can see, each list item is enclosed within an
- tag, and the entire list is contained within a
- tag. By default, unordered lists render as bullet points, which helps to differentiate them from ordered lists.
- tag can contain more than just text. It can also encapsulate other HTML elements, creating rich and varied lists. Let's explore this with an example:
- Apples
- Bananas
- Cherries
In this list, list items include bold text, a link, and a heading, demonstrating the flexibility of the
- and
- tags.
Creating nested unordered lists
You can also create nested unordered lists by placing a
- tag inside another list item. This can be useful for creating lists with sub-lists, like a hierarchical menu:
- Fruits
- Apples
- Bananas
- Vegetables
- Lettuce
- Tomatoes
- Circles
- Squares
- Triangles
- Trees
- Forests
- Mountains
- tags can greatly improve your HTML skills and help you create more engaging and readable content. Practice with different list types, styles, and nesting levels to gain a deeper understanding of these versatile tools.
The resulting list will show 'Fruits' and 'Vegetables' as main list items, with their respective sub-items indented beneath them.
Customizing list styling
Now that we understand how to create unordered lists, let's explore how to customize their styling. By default, unordered lists have filled bullet points, but you can replace these with custom list markers by using CSS.
Using list-style-type property
CSS provides the list-style-type property for customizing list markers. Here's an example:
In this example, the list-style-type property is set to 'circle', changing the list markers to hollow circles.
Using CSS classes
For more complex styling, you can use CSS classes. Here's an example:
In this example, a CSS class named 'custom-list' is defined to remove the default list markers, add padding, and use a custom icon (a tree emoji) for each list item.
Understanding and mastering the use of the
- and
- Fruits
Embedding elements within list items
The
- tag can contain more than just text. It can also encapsulate other HTML elements, creating rich and varied lists. Let's explore this with an example:
- tags:
Before we delve into the examples, it's crucial to understand that the
- tag works in tandem with the