HTML - <ul>
The HTML <ul>
element (or HTML Unordered List Element)
represents an unordered list of items, namely a collection of items that do not have a numerical ordering, and their order in the list is meaningless. Typically, unordered-list items are displayed with a bullet, which can be of several forms, like a dot, a circle or a squared. The bullet style is not defined in the HTML description of the page, but in its associated CSS, using the list-style-type
property.
Examples
Simple example
<ul> <li>first item</li> <li>second item</li> <li>third item</li> </ul>
Above HTML will output:
- first item
- second item
- third item
Nesting list
<ul> <li>first item</li> <li>second item <!-- Look, the closing </li> tag is not placed here! --> <ul> <li>second item first subitem</li> <li>second item second subitem <!-- Same for the second nested unordered list! --> <ul> <li>second item second subitem first sub-subitem</li> <li>second item second subitem second sub-subitem</li> <li>second item second subitem third sub-subitem</li> </ul> </li> <!-- Closing </li> tag for the li that contains the third unordered list --> <li>second item third subitem</li> </ul> </li> <!-- Here is the closing </li> tag --> <li>third item</li> </ul>
Above HTML will output:
- first item
- second item
- second item first subitem
- second item second subitem
- second item second subitem first sub-subitem
- second item second subitem second sub-subitem
- second item second subitem third sub-subitem
- second item third subitem
- third item
Nested <ul> and <ol>
<ul> <li>first item</li> <li>second item <!-- Look, the closing </li> tag is not placed here! --> <ol> <li>second item first subitem</li> <li>second item second subitem</li> <li>second item third subitem</li> </ol> </li> <!-- Here is the closing </li> tag --> <li>third item</li> </ul>
Above HTML will output:
- first item
- second item
- second item first subitem
- second item second subitem
- second item third subitem
- third item
Description
The HTML <ul>
element (or HTML Unordered List Element)
represents an unordered list of items, namely a collection of items that do not have a numerical ordering, and their order in the list is meaningless. Typically, unordered-list items are displayed with a bullet, which can be of several forms, like a dot, a circle or a squared. The bullet style is not defined in the HTML description of the page, but in its associated CSS, using the list-style-type
property.
There is no limitation to the depth and imbrication of lists defined with the <ol>
and <ul>
elements.
<ol>
and <ul>
elements both represent a list of items. They differ in that, with the <ol>
element, the order is meaningful. As a rule of thumb to determine which one to use, try changing the order of the list items; if the meaning is changed, the <ol>
element should be used, otherwise you can use <ul>
.Content categories | Flow content |
Permitted content | zero or more <li> elements, eventually mixed with <ol> and <ul> elements. |
Tag omission | none, both the start tag and the end tag are mandatory |
Permitted parent elements | any element that accept flowing content |
DOM Interface | HTMLUListElement |
See Also
- Other list-related HTML Elements:
<ol>
,<li>
,<menu>
and the obsolete<dir>
; - CSS properties that may be specially useful to style the <ul> element:
- the list-style property, useful to choose the way the ordinal is displayed,
- CSS counters, useful to handle complex nested lists,
- the line-height property, useful to simulate the deprecated
compact
attribute, - the margin property, useful to control the indent of the list.
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/ul