List group

List groups are a flexible and powerful component for displaying a series of content. Modify and extend them to support just about any content within.

Basic example

The most basic list group is an unordered list with list items and the proper classes. Build upon it with the options that follow, or with your own CSS as needed.

  • Cras justo odio
  • Dapibus ac facilisis in
  • Morbi leo risus
  • Porta ac consectetur ac
  • Vestibulum at eros
<ul class="list-group_sth">
  <li class="list-group-item_sth">Cras justo odio</li>
  <li class="list-group-item_sth">Dapibus ac facilisis in</li>
  <li class="list-group-item_sth">Morbi leo risus</li>
  <li class="list-group-item_sth">Porta ac consectetur ac</li>
  <li class="list-group-item_sth">Vestibulum at eros</li>
</ul>

Active items

Add .active_sth to a .list-group-item_sth to indicate the current active selection.

  • Cras justo odio
  • Dapibus ac facilisis in
  • Morbi leo risus
  • Porta ac consectetur ac
  • Vestibulum at eros
<ul class="list-group_sth">
  <li class="list-group-item_sth active_sth">Cras justo odio</li>
  <li class="list-group-item_sth">Dapibus ac facilisis in</li>
  <li class="list-group-item_sth">Morbi leo risus</li>
  <li class="list-group-item_sth">Porta ac consectetur ac</li>
  <li class="list-group-item_sth">Vestibulum at eros</li>
</ul>

Disabled items

Add .disabled_sth to a .list-group-item_sth to make it appear disabled. Note that some elements with .disabled_sth will also require custom JavaScript to fully disable their click events (e.g., links).

  • Cras justo odio
  • Dapibus ac facilisis in
  • Morbi leo risus
  • Porta ac consectetur ac
  • Vestibulum at eros
<ul class="list-group_sth">
  <li class="list-group-item_sth disabled_sth">Cras justo odio</li>
  <li class="list-group-item_sth">Dapibus ac facilisis in</li>
  <li class="list-group-item_sth">Morbi leo risus</li>
  <li class="list-group-item_sth">Porta ac consectetur ac</li>
  <li class="list-group-item_sth">Vestibulum at eros</li>
</ul>

Use <a>s or <button>s to create actionable list group items with hover, disabled, and active states by adding .list-group-item-action_sth. We separate these pseudo-classes to ensure list groups made of non-interactive elements (like <li>s or <div>s) don’t provide a click or tap affordance.

Be sure to not use the standard .btn_sth classes here.

<div class="list-group_sth">
  <a href="#" class="list-group-item_sth list-group-item-action_sth active_sth">
    Cras justo odio
  </a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth">Dapibus ac facilisis in</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth">Morbi leo risus</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth">Porta ac consectetur ac</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth disabled_sth">Vestibulum at eros</a>
</div>

With <button>s, you can also make use of the disabled attribute instead of the .disabled_sth class. Sadly, <a>s don’t support the disabled attribute.

<div class="list-group_sth">
  <button type="button" class="list-group-item_sth list-group-item-action_sth active_sth">
    Cras justo odio
  </button>
  <button type="button" class="list-group-item_sth list-group-item-action_sth">Dapibus ac facilisis in</button>
  <button type="button" class="list-group-item_sth list-group-item-action_sth">Morbi leo risus</button>
  <button type="button" class="list-group-item_sth list-group-item-action_sth">Porta ac consectetur ac</button>
  <button type="button" class="list-group-item_sth list-group-item-action_sth" disabled>Vestibulum at eros</button>
</div>

Contextual classes

Use contextual classes to style list items with a stateful background and color.

  • Dapibus ac facilisis in
  • This is a primary list group item
  • This is a secondary list group item
  • This is a success list group item
  • This is a danger list group item
  • This is a warning list group item
  • This is a info list group item
  • This is a light list group item
  • This is a dark list group item
<ul class="list-group_sth">
  <li class="list-group-item_sth">Dapibus ac facilisis in</li>

  
  <li class="list-group-item_sth list-group-item-primary_sth">This is a primary list group item</li>
  <li class="list-group-item_sth list-group-item-secondary_sth">This is a secondary list group item</li>
  <li class="list-group-item_sth list-group-item-success_sth">This is a success list group item</li>
  <li class="list-group-item_sth list-group-item-danger_sth">This is a danger list group item</li>
  <li class="list-group-item_sth list-group-item-warning_sth">This is a warning list group item</li>
  <li class="list-group-item_sth list-group-item-info_sth">This is a info list group item</li>
  <li class="list-group-item_sth list-group-item-light_sth">This is a light list group item</li>
  <li class="list-group-item_sth list-group-item-dark_sth">This is a dark list group item</li>
</ul>

Contextual classes also work with .list-group-item-action_sth. Note the addition of the hover styles here not present in the previous example. Also supported is the .active_sth state; apply it to indicate an active selection on a contextual list group item.

<div class="list-group_sth">
  <a href="#" class="list-group-item_sth list-group-item-action_sth">Dapibus ac facilisis in</a>

  
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-primary_sth">This is a primary list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-secondary_sth">This is a secondary list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-success_sth">This is a success list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-danger_sth">This is a danger list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-warning_sth">This is a warning list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-info_sth">This is a info list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-light_sth">This is a light list group item</a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth list-group-item-dark_sth">This is a dark list group item</a>
</div>

Conveying meaning to assistive technologies

Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies – such as screen readers. Ensure that information denoted by the color is either obvious from the content itself (e.g. the visible text), or is included through alternative means, such as additional text hidden with the .sr-only class.

With badges

Add badges to any list group item to show unread counts, activity, and more with the help of some utilities.

  • Cras justo odio 14
  • Dapibus ac facilisis in 2
  • Morbi leo risus 1
<ul class="list-group_sth">
  <li class="list-group-item_sth d-flex_sth justify-content-between_sth align-items-center_sth">
    Cras justo odio
    <span class="badge_sth badge-primary_sth badge-pill_sth">14</span>
  </li>
  <li class="list-group-item_sth d-flex_sth justify-content-between_sth align-items-center_sth">
    Dapibus ac facilisis in
    <span class="badge_sth badge-primary_sth badge-pill_sth">2</span>
  </li>
  <li class="list-group-item_sth d-flex_sth justify-content-between_sth align-items-center_sth">
    Morbi leo risus
    <span class="badge_sth badge-primary_sth badge-pill_sth">1</span>
  </li>
</ul>

Custom content

Add nearly any HTML within, even for linked list groups like the one below, with the help of flexbox utilities.

<div class="list-group_sth">
  <a href="#" class="list-group-item_sth list-group-item-action_sth flex-column_sth align-items-start_sth active_sth">
    <div class="d-flex_sth w-100_sth justify-content-between_sth">
      <h5 class="mb-1_sth">List group item heading</h5>
      <small>3 days ago</small>
    </div>
    <p class="mb-1_sth">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
    <small>Donec id elit non mi porta.</small>
  </a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth flex-column_sth align-items-start_sth">
    <div class="d-flex_sth w-100_sth justify-content-between_sth">
      <h5 class="mb-1_sth">List group item heading</h5>
      <small class="text-muted_sth">3 days ago</small>
    </div>
    <p class="mb-1_sth">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
    <small class="text-muted_sth">Donec id elit non mi porta.</small>
  </a>
  <a href="#" class="list-group-item_sth list-group-item-action_sth flex-column_sth align-items-start_sth">
    <div class="d-flex_sth w-100_sth justify-content-between_sth">
      <h5 class="mb-1_sth">List group item heading</h5>
      <small class="text-muted_sth">3 days ago</small>
    </div>
    <p class="mb-1_sth">Donec id elit non mi porta gravida at eget metus. Maecenas sed diam eget risus varius blandit.</p>
    <small class="text-muted_sth">Donec id elit non mi porta.</small>
  </a>
</div>

JavaScript behavior

Use the tab JavaScript plugin—include it individually or through the compiled bootstrap.js file—to extend our list group to create tabbable panes of local content.

<div class="row_sth">
  <div class="col-4_sth">
    <div class="list-group_sth" id="list-tab" role="tablist">
      <a class="list-group-item_sth list-group-item-action_sth active_sth" id="list-home-list" data-toggle="list" href="#list-home" role="tab" aria-controls="home">Home</a>
      <a class="list-group-item_sth list-group-item-action_sth" id="list-profile-list" data-toggle="list" href="#list-profile" role="tab" aria-controls="profile">Profile</a>
      <a class="list-group-item_sth list-group-item-action_sth" id="list-messages-list" data-toggle="list" href="#list-messages" role="tab" aria-controls="messages">Messages</a>
      <a class="list-group-item_sth list-group-item-action_sth" id="list-settings-list" data-toggle="list" href="#list-settings" role="tab" aria-controls="settings">Settings</a>
    </div>
  </div>
  <div class="col-8_sth">
    <div class="tab-content_sth" id="nav-tabContent">
      <div class="tab-pane_sth fade_sth show_sth active_sth" id="list-home" role="tabpanel" aria-labelledby="list-home-list">...</div>
      <div class="tab-pane_sth fade_sth" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">...</div>
      <div class="tab-pane_sth fade_sth" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">...</div>
      <div class="tab-pane_sth fade_sth" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">...</div>
    </div>
  </div>
</div>

Using data attributes

You can activate a list group navigation without writing any JavaScript by simply specifying data-toggle_sth="list" or on an element. Use these data attributes on .list-group-item_sth.

<!-- List group -->
<div class="list-group_sth" id="myList" role="tablist">
  <a class="list-group-item_sth list-group-item-action_sth active_sth" data-toggle="list" href="#home" role="tab">Home</a>
  <a class="list-group-item_sth list-group-item-action_sth" data-toggle="list" href="#profile" role="tab">Profile</a>
  <a class="list-group-item_sth list-group-item-action_sth" data-toggle="list" href="#messages" role="tab">Messages</a>
  <a class="list-group-item_sth list-group-item-action_sth" data-toggle="list" href="#settings" role="tab">Settings</a>
</div>

<!-- Tab panes -->
<div class="tab-content_sth">
  <div class="tab-pane_sth activ_sthe" id="home" role="tabpanel">...</div>
  <div class="tab-pane_sth" id="profile" role="tabpanel">...</div>
  <div class="tab-pane_sth" id="messages" role="tabpanel">...</div>
  <div class="tab-pane_sth" id="settings" role="tabpanel">...</div>
</div>

Via JavaScript

Enable tabbable list item via JavaScript (each list item needs to be activated individually):

$sth('#myList a').on('click', function (e) {
  e.preventDefault()
  $sth(this).tab('show')
})

You can activate individual list item in several ways:

$sth('#myList a[href="#profile"]').tab('show') // Select tab by name
$sth('#myList a:first').tab('show') // Select first tab
$sth('#myList a:last').tab('show') // Select last tab
$sth('#myList li:eq(2) a').tab('show') // Select third tab (0-indexed)

Fade effect

To make tabs panel fade in, add .fade_sth to each .tab-pane_sth. The first tab pane must also have .show_sth to make the initial content visible.

<div class="tab-content_sth">
  <div class="tab-pane_sth fade_sth show_sth active_sth" id="home" role="tabpanel">...</div>
  <div class="tab-pane_sth fade_sth" id="profile" role="tabpanel">...</div>
  <div class="tab-pane_sth fade_sth" id="messages" role="tabpanel">...</div>
  <div class="tab-pane_sth fade_sth" id="settings" role="tabpanel">...</div>
</div>

Methods

$sth().tab

Activates a list item element and content container. Tab should have either a data-target_sth or an href targeting a container node in the DOM.

<div class="list-group_sth" id="myList" role="tablist">
  <a class="list-group-item_sth list-group-item-action_sth active_sth" data-toggle="list" href="#home" role="tab">Home</a>
  <a class="list-group-item_sth list-group-item-action_sth" data-toggle="list" href="#profile" role="tab">Profile</a>
  <a class="list-group-item_sth list-group-item-action_sth" data-toggle="list" href="#messages" role="tab">Messages</a>
  <a class="list-group-item_sth list-group-item-action_sth" data-toggle="list" href="#settings" role="tab">Settings</a>
</div>

<div class="tab-content_sth">
  <div class="tab-pane_sth active_sth" id="home" role="tabpanel">...</div>
  <div class="tab-pane_sth" id="profile" role="tabpanel">...</div>
  <div class="tab-pane_sth" id="messages" role="tabpanel">...</div>
  <div class="tab-pane_sth" id="settings" role="tabpanel">...</div>
</div>

<script>
  $sth(function () {
    $sth('#myList a:last').tab('show')
  })
</script>

.tab(‘show’)

Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. Returns to the caller before the tab pane has actually been shown (for example, before the shown.bs.tab event occurs).

$sth('#someListItem').tab('show')

Events

When showing a new tab, the events fire in the following order:

  1. hide.bs.tab (on the current active tab)
  2. show.bs.tab (on the to-be-shown tab)
  3. hidden.bs.tab (on the previous active tab, the same one as for the hide.bs.tab event)
  4. shown.bs.tab (on the newly-active just-shown tab, the same one as for the show.bs.tab event)

If no tab was already active, the hide.bs.tab and hidden.bs.tab events will not be fired.

Event type Description
show.bs.tab This event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
shown.bs.tab This event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
hide.bs.tab This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use event.target and event.relatedTarget to target the current active tab and the new soon-to-be-active tab, respectively.
hidden.bs.tab This event fires after a new tab is shown (and thus the previous active tab is hidden). Use event.target and event.relatedTarget to target the previous active tab and the new active tab, respectively.
$sth('a[data-toggle="list"]').on('shown.bs.tab', function (e) {
  e.target // newly activated tab
  e.relatedTarget // previous active tab
})