HTML Lists: Unordered, Ordered and Description Lists
Lists are everywhere on the web: navigation menus, feature lists, steps in a recipe, glossaries. HTML has three list types, and choosing the right one tells browsers and assistive technology how the items relate.
Unordered lists
<ul> holds items whose order does not matter, each in an <li>. Browsers draw bullets by default. Navigation menus are usually unordered lists styled with CSS to remove the bullets and line the links up horizontally.
Ordered lists
<ol> is for items where sequence matters, such as installation steps or a top-ten ranking. Browsers number them automatically, so inserting a step renumbers everything. Useful attributes:
start="5"begins counting at 5.reversedcounts down.type="A","a","I"or"i"switches to letters or Roman numerals.
Expected page text
Shopping list Notebook Pens Blue Black Install steps Download Python Run the installer Open a terminal Glossary HTML The structure of a page CSS The presentation of a page
Nesting
To create a sub-list, put a complete <ul> or <ol> inside an <li>, after that item's text, as the "Pens" item does. A list placed directly inside another list, outside any <li>, is invalid. The only elements allowed as direct children of <ul> and <ol> are <li> (plus script-supporting elements).
Description lists
<dl> holds groups of terms (<dt>) and descriptions (<dd>). It fits glossaries, metadata such as "Author: Ethan Cole", and FAQ-style pairs. A term can have several descriptions, and several terms can share one description.
Bullets and numbers are presentation
The bullets and numbers are drawn by the browser, not part of the text, which is why the expected page text above contains only the item contents. Change their look with CSS (list-style-type), not by typing characters like "1." or "-" into the items. Screen readers announce lists with their number of items, which helps listeners know what is coming.
Common mistakes
- Putting text or other elements directly inside
<ul>without an<li>. - Using an ordered list when order is irrelevant, or typing numbers by hand.
- Nesting a sub-list outside the
<li>it belongs to.
Summary
<ul>for unordered items,<ol>for sequences; items go in<li>.start,reversedandtypeadjust numbering.- Nest a sub-list inside an
<li>. <dl>pairs terms (<dt>) with descriptions (<dd>).
Quiz: Lists