Scroll to top
4 min read

The <ul> element in HTML stands for “unordered list” and is used to create lists of items where the order of items doesn’t matter. It’s a fundamental part of structuring content in web documents, allowing you to present information in a visually organized manner.

Syntax

The <ul> element consists of one or more list items (<li>) as its children. Here’s a basic example of the syntax:

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

Example

Here’s another example of how <ul> element works in a real-world scenario:

In this example, an unordered list displays a list of ingredients for a recipe. The list items (<li>) represent each ingredient and are bulleted (default browser styling) to indicate that they are part of an unordered list.

Attributes

The <ul> element does not have many attributes; its primary purpose is to organize and structure content as a list. It can be styled and modified using CSS to change its appearance. It does support global attributes.

Styling Considerations

When it comes to styling the <ul> element, there are some best practices to keep in mind to make sure your lists are visually appealing and user-friendly:

List Marker Styles

By default, browsers render <ul> elements with bullet points as list markers. You can customize the list marker styles using CSS. Common styles include changing the shape (e.g., disc, square, circle), size, color, and position of the markers. 

1
ul {
2
  list-style-type: disc; /* Change marker shape */
3
  list-style-position: inside; /* Place markers relative to list item content */
4
}

Try these properties yourself! Notice how each <li> has a border to highlight its boundaries.

Spacing and Margins

Adjust the spacing between list items and margins around the entire list to control the visual separation between items and surrounding content.

1
ul {
2
  margin: 0; /* Remove default margin */
3
  padding: 0; /* Remove default padding */
4
}
5
6
li {
7
  margin-bottom: 10px; /* Add space between list items */
8
}

Typography

Define the font size, typeface, and text color for list items to ensure readability and consistency with your overall page design. 

1
ul {
2
  font-family: Arial, sans-serif;
3
  font-size: 16px;
4
  color: #333;
5
}

Indentation

Use CSS to control the indentation of the entire list and individual list items. Adjusting the indentation can create more legibility in a large body of text.

1
ul {
2
  padding-left: 20px; /* Indent the entire list */
3
}
4
5
ul ul {
6
  padding-left: 30px; /* Further indent nested lists */
7
}

Background and Borders

Apply background colors, borders, or other visual effects to highlight or differentiate lists from the surrounding content. This can be particularly useful for navigation menus or callout lists.

1
ul {
2
  background-color: #f9f9f9;
3
  border: 1px solid #ccc;
4
  border-radius: 5px;
5
}

Responsive Design

Consider how your lists will appear on different screen sizes. Use media queries and responsive design principles to adapt the styling of lists for mobile and desktop devices.

Accessibility

Ensure that your styling choices do not compromise accessibility. Maintain sufficient contrast between text and background colors, and avoid using solely color cues to convey information (e.g., for list markers). Test your lists with screen readers to ensure they are navigable and understandable for all users.

Content

The <ul> element accepts one or more <li> elements as its children. Each <li> element represents an item in the list. The content within the <li> element can include text, links, images, or any other HTML elements.

Did You Know?

  • The <ul> element is part of a family of list-related HTML elements, including <ol> (ordered list) and <dl> (description list). Each serves a different purpose for structuring content.
  • By default, browsers typically render <ul> elements with bullet points as the list markers. The appearance of these markers can be customized using CSS.
  • Lists created with <ul> are often used for navigation menus, FAQs, and any content where the order of items is not significant.

Learn More

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.