Bootstrap 5 Lists: Unordered, Ordered and Description Lists

Bootstrap does not need a class to style an ordinary list. Its Reboot stylesheet gives <ul>, <ol> and <dl> consistent spacing across browsers, and a handful of classes cover the cases where you want something different: no bullets, items on one line, or terms and descriptions side by side.

All examples need only the stylesheet: https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css.

Plain lists

<h2>Unordered list</h2>
<ul>
  <li>Home</li>
  <li>All posts</li>
  <li>Bootstrap examples
    <ul>
      <li>Example 1</li>
      <li>Example 2</li>
    </ul>
  </li>
  <li>Contact</li>
</ul>

<h2>Ordered list</h2>
<ol>
  <li>Home</li>
  <li>All posts</li>
  <li>Bootstrap examples
    <ol>
      <li>Example 1</li>
      <li>Example 2</li>
    </ol>
  </li>
  <li>Contact</li>
</ol>

Reboot removes the top margin from lists, keeps a 1rem bottom margin, and sets a 2rem left padding for the bullets or numbers. Nested lists get no bottom margin, so a sub-list sits tight against the next item of its parent. The nested <ul> or <ol> must go inside an <li>, as above; placing it directly inside the outer list is invalid HTML, even though browsers render it.

Lists without bullets

.list-unstyled removes the bullets and the left padding:

<ul class="list-unstyled">
  <li>Home</li>
  <li>Bootstrap examples
    <ul>
      <li>Example 1</li>
      <li>Example 2</li>
    </ul>
  </li>
</ul>

The class only affects the list it is on. The nested list above keeps its bullets and indentation; add .list-unstyled to it as well if you want it plain.

One accessibility trap: Safari with VoiceOver stops announcing a list as a list when its bullets are removed with CSS. If the number of items matters to users (a menu, search results), add role="list" to the <ul> to restore it.

Description lists

A description list pairs terms (<dt>) with their descriptions (<dd>). Reboot makes the terms bold and removes the browser’s default indentation from the descriptions:

<dl>
  <dt>What is HTML?</dt>
  <dd>HTML (HyperText Markup Language) is the standard markup language for web pages.</dd>
  <dt>What is Bootstrap?</dt>
  <dd>Bootstrap is an open source CSS and JavaScript toolkit for building responsive websites.</dd>
</dl>

Horizontal description lists

Bootstrap 3 had a .dl-horizontal class for terms and descriptions side by side. It was removed in Bootstrap 4; the grid does the job now. Make the <dl> a row and give the <dt> and <dd> column classes:

<dl class="row">
  <dt class="col-sm-3">What is HTML?</dt>
  <dd class="col-sm-9">HTML (HyperText Markup Language) is the standard markup language for web pages.</dd>

  <dt class="col-sm-3 text-truncate">What is Bootstrap and who maintains it?</dt>
  <dd class="col-sm-9">An open source CSS and JavaScript toolkit, started at Twitter and now maintained by a core team on GitHub.</dd>
</dl>

Below the sm breakpoint (576px) the columns stack, so phones get the normal layout. .text-truncate cuts a long term off with an ellipsis instead of letting it wrap. Use it with care: the hidden part of the text is lost for sighted users, so add a title attribute or keep terms short.

When a list is really a component

If your list is a navigation menu, use Bootstrap’s nav or navbar components inside a <nav> element rather than styling a plain list yourself. If it is a set of clickable items, badges or selectable rows, a list group is usually the better fit.

Related examples

Leave a Comment