HTML ul
Definition of an Unordered List
An unordered list is a way to present a set of related items without emphasizing their order. In HTML, it is created using the <ul> tag, and each item within the list is enclosed in <li> tags. These items appear as bulleted points by default, making them easily recognizable.
Purpose of Using Unordered Lists in HTML
Unordered lists help in organizing and displaying information clearly. They group related items without implying any specific order, enhancing readability. This format is ideal for menus, steps, options, and other related information.
Creating Unordered Lists
To create an unordered list in HTML:
Example:
By default, these items will be displayed with bullet points.
Customizing Unordered Lists with CSS
You can change the appearance of the list item markers using CSS. For example, to change the bullet color:
This code changes the bullet style to a square and the bullet color to red.
Syntax for Creating an Unordered List in HTML
To create an unordered list, use the following syntax:
The <ul> tag acts as the container, and the <li> tags represent each list item.
Adding List Items to an Unordered List Using <li> Elements
To add items to an unordered list, follow these steps:
Example:
Nesting List Items Within an Unordered List
You can create subcategories by nesting lists within another list:
This nesting helps in creating a hierarchical structure.
Types of Lists in HTML
HTML provides three main types of lists:
Understanding Different Types of Lists
- Unordered Lists (<ul>): Use bullet points to display items.
- Ordered Lists (<ol>): Use numbers or letters to display items in a sequence.
- Description Lists (<dl>): Use <dt> for terms and <dd> for descriptions.
CSS Properties for Styling Lists
CSS offers several properties to style lists, including:
- list-style-type: Changes the bullet style (e.g., disc, circle, square).
- list-style-image: Uses an image as the bullet.
- background-color: Sets the background color for the list or items.
- padding, margin, font-size, and color: Customize spacing, size, and color.
Introduction to the list-style-type Property in CSS
The list-style-type property customizes the bullet type for list items. Common values include:
- disc: Default filled circle.
- circle: Hollow circle.
- square: Filled square.
- none: No marker.
Example:
Customizing Bullet Styles for Unordered Lists
To customize bullet styles, use the list-style-type property in the <ul> tag:
This example changes the default bullet to a square.
Master Frontend by choosing your ideal learning course
Introduction to HTML and CSS
Frontend Developer