Mastering UL & LI Tags: HTML's Complete List Formatting
The
- and
- tags in HTML are fundamental elements used for creating unordered lists on the web. When you want to display a collection of related items without any particular order, these tags come into play. Let's explore them in detail.
Before diving into the specific usage, it's crucial to understand that
- stands for unordered list, and
- stands for list item. The
- tag defines an unordered list, and the
- tag defines each list item. Now, let's see how to use them in action.
Creating Unordered Lists
To create an unordered list, you wrap the
- tag around the list items. Here's a simple example:
```html
- Item 1
- Item 2
- Item 3
- Parent item 1
- Child item 1
- Child item 2
- Parent item 2
- tags accept several attributes that can help you customize the list's appearance and behavior. One useful attribute is 'id' or 'class', which allows you to apply specific styles using CSS.
id Attribute
The 'id' attribute is useful when you want to apply unique styles to a single list or item. Here's an example:
```html- Item 1
- Item 2
class Attribute
The 'class' attribute is used to apply the same styles to multiple lists or items. You can use it to group related items together.
```html- Item 1
- Item 2
Finally, using
- and
- tags efficiently can greatly improve the readability and accessibility of your HTML documents. Kudos to you for taking the time to learn and understand these essential HTML elements!
Default Style
By default, unordered lists use bullets to mark each item. The bullet points are square by default, but you can change them using the CSS property 'list-style-type'. The most common alternatives are 'circle' and 'disc'.
Nested Unordered Lists
You can nest unordered lists to create hierarchical structures. Here's an example of a nested unordered list:
```htmlCustomizing List Items with Attributes
- and
- tag defines each list item. Now, let's see how to use them in action.
- stands for list item. The