Skip to main contentSkip to docs navigation

Chassis

Group related content in bordered lists with active and disabled items, actionable items, numbered, flush and horizontal layouts, and context colors.

@layer components
JavaScript is optional
Container queries
Context tokens

Introduction

Lists group a series of related items in a bordered container. Items are plain content by default, and become actionable as links or buttons, hold custom content and other components, and take the context colors.

Basic structure

A list is an element with the .list class, typically a <ul>, and a .list-item for each entry. The container sets the custom properties of the component, and the items draw the borders, the padding and the rounded outer corners.

  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
HTML
<ul class="list">
  <li class="list-item">An item</li>
  <li class="list-item">A second item</li>
  <li class="list-item">A third item</li>
  <li class="list-item">A fourth item</li>
  <li class="list-item">And a fifth one</li>
</ul>

Active state

Apply the .active class to a .list-item to mark the current selection. Add aria-current="true" so assistive technologies announce the active item.

  • An active item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
HTML
<ul class="list">
  <li class="list-item active" aria-current="true">An active item</li>
  <li class="list-item">A second item</li>
  <li class="list-item">A third item</li>
  <li class="list-item">A fourth item</li>
  <li class="list-item">And a fifth one</li>
</ul>

Disabled state

Apply the .disabled class to a .list-item to style it as disabled. Add aria-disabled="true" to convey the state to assistive technologies.

The .disabled class changes the appearance and sets pointer-events: none. A link stays reachable and operable with the keyboard: omit its href, or prevent its activation with JavaScript.

  • A disabled item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
HTML
<ul class="list">
  <li class="list-item disabled" aria-disabled="true">A disabled item</li>
  <li class="list-item">A second item</li>
  <li class="list-item">A third item</li>
  <li class="list-item">A fourth item</li>
  <li class="list-item">And a fifth one</li>
</ul>

Interactive elements

Use <a> or <button> elements with the .list-action class for actionable items. The class adds the hover, focus, pressed and disabled states to an item, on a single .list-item or on the .list for all of its items.

The interactive states are opt-in, so items that are not links or buttons give no hover feedback and read-only content is not mistaken for an action.

HTML
<div class="list">
  <a href="#" class="list-item list-action active" aria-current="true">
    The current link item
  </a>
  <a href="#" class="list-item list-action">A second link item</a>
  <a href="#" class="list-item list-action">A third link item</a>
  <a href="#" class="list-item list-action">A fourth link item</a>
  <a class="list-item list-action disabled" aria-disabled="true">A disabled link item</a>
</div>

Anchors and buttons both work as actionable list items, and differ in meaning:

  • Use <a> elements when the action navigates to a new location or resource
  • Use <button> elements when the action triggers an in-page behavior or state change

A <button> takes the native disabled attribute, which styles the item and prevents interaction. An <a> has no such attribute: the .disabled class styles it, and omitting href keeps it out of the tab order.

HTML
<div class="list">
  <button type="button" class="list-item list-action active" aria-current="true">
    The current button
  </button>
  <button type="button" class="list-item list-action">A second button item</button>
  <button type="button" class="list-item list-action">A third button item</button>
  <button type="button" class="list-item list-action">A fourth button item</button>
  <button type="button" class="list-item list-action" disabled>A disabled button item</button>
</div>

Layout options

Modifier classes on the .list element change its borders, its padding, its numbering and the direction of its items.

Flush list

Apply .flush to remove the outer borders and the rounded corners, so the items run edge to edge. It suits a list inside another component, such as a card.

  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
HTML
<ul class="list flush">
  <li class="list-item">An item</li>
  <li class="list-item">A second item</li>
  <li class="list-item">A third item</li>
  <li class="list-item">A fourth item</li>
  <li class="list-item">And a fifth one</li>
</ul>

Plain layout

Apply .plain to remove the outer borders, the rounded corners and the horizontal padding. It suits a list that is the main content of a page, such as search results or a feed.

  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
HTML
<ul class="list plain">
  <li class="list-item">An item</li>
  <li class="list-item">A second item</li>
  <li class="list-item">A third item</li>
  <li class="list-item">A fourth item</li>
  <li class="list-item">And a fifth one</li>
</ul>

Both .flush and .plain remove the outer borders and the rounded corners. .plain also removes the horizontal padding of the items.

Numbered lists

Apply .numbered to number the items of a list. Use an <ol> element for the semantics: the numbers themselves are generated with CSS, not by the browser's list markers.

The numbering uses CSS counters: counter-reset on the .list element, and a ::before pseudo-element with counter-increment on each item. The number is part of the item's content box, so it stays in place next to content of any complexity.

  1. A list item
  2. A list item
  3. A list item
HTML
<ol class="list numbered">
  <li class="list-item">A list item</li>
  <li class="list-item">A list item</li>
  <li class="list-item">A list item</li>
</ol>

Numbered items hold custom content as well, here laid out with flex utilities.

  1. Subheading
    Content for list item
    14
  2. Subheading
    Content for list item
    14
  3. Subheading
    Content for list item
    14
HTML
<ol class="list numbered">
  <li class="list-item d-flex justify-content-between align-items-start">
    <div class="ms-xs me-auto">
      <div class="font-strong">Subheading</div>
      Content for list item
    </div>
    <span class="badge primary">14</span>
  </li>
  <li class="list-item d-flex justify-content-between align-items-start">
    <div class="ms-xs me-auto">
      <div class="font-strong">Subheading</div>
      Content for list item
    </div>
    <span class="badge primary">14</span>
  </li>
  <li class="list-item d-flex justify-content-between align-items-start">
    <div class="ms-xs me-auto">
      <div class="font-strong">Subheading</div>
      Content for list item
    </div>
    <span class="badge primary">14</span>
  </li>
</ol>

Horizontal layout

.horizontal switches a list from column to row layout. Adjacent items share a single border edge, and outer corners remain rounded while inner corners are squared off.

Responsive variants use container queries — each .{breakpoint}:horizontal class activates at or above the specified container width. Wrap the list in .contains-inline to establish the container context. Resize the example below to see the breakpoint transitions.

.horizontal cannot be combined with .flush — the flush variant removes inline borders that separate items in the horizontal layout.

  • An item
  • A second item
  • A third item
  • An item
  • A second item
  • A third item
  • An item
  • A second item
  • A third item
  • An item
  • A second item
  • A third item
HTML
<div class="contains-inline">
  <ul class="list horizontal mb-md">
    <li class="list-item">An item</li>
    <li class="list-item">A second item</li>
    <li class="list-item">A third item</li>
  </ul>
  <ul class="list sm:horizontal mb-md">
    <li class="list-item">An item</li>
    <li class="list-item">A second item</li>
    <li class="list-item">A third item</li>
  </ul>
  <ul class="list md:horizontal mb-md">
    <li class="list-item">An item</li>
    <li class="list-item">A second item</li>
    <li class="list-item">A third item</li>
  </ul>
  <ul class="list lg:horizontal mb-md">
    <li class="list-item">An item</li>
    <li class="list-item">A second item</li>
    <li class="list-item">A third item</li>
  </ul>
</div>

Apply .flex-fill or .flex-grow-1 to list items to stretch them across the full list width:

  • .flex-fill — items share the available width equally, regardless of content length
  • .flex-grow-1 — items grow from their natural content width; items with longer content end up wider
  • An item
  • Second item
  • And the longer third item
  • An item
  • Second item
  • And the longer third item
HTML
<ul class="list horizontal mb-md">
  <li class="list-item flex-fill">An item</li>
  <li class="list-item flex-fill">Second item</li>
  <li class="list-item flex-fill">And the longer third item</li>
</ul>
<ul class="list horizontal">
  <li class="list-item flex-grow-1">An item</li>
  <li class="list-item flex-grow-1">Second item</li>
  <li class="list-item flex-grow-1">And the longer third item</li>
</ul>

Component combinations

List items hold other components and custom markup: badges, headings and text, and form controls.

Items with badges

Add a badge to a list item to show a count or a status. The flex utilities on the item push the badge to the end and center it vertically.

  • A list item 14
  • A second list item 2
  • A third list item 1
HTML
<ul class="list">
  <li class="list-item d-flex justify-content-between align-items-center">
    A list item
    <span class="badge primary">14</span>
  </li>
  <li class="list-item d-flex justify-content-between align-items-center">
    A second list item
    <span class="badge primary">2</span>
  </li>
  <li class="list-item d-flex justify-content-between align-items-center">
    A third list item
    <span class="badge primary">1</span>
  </li>
</ul>

Rich content

A list item accepts nearly any markup: headings, paragraphs, metadata. Flexbox utilities lay the content out inside the item.

HTML
<div class="list">
  <a href="#" class="list-item list-action active" aria-current="true">
    <div class="d-flex w-100 justify-content-between">
      <h4 class="font-lg mb-2xs">List item heading</h4>
      <small>3 days ago</small>
    </div>
    <p class="mb-2xs">Some placeholder content in a paragraph.</p>
    <small>And some small print.</small>
  </a>
  <a href="#" class="list-item list-action">
    <div class="d-flex w-100 justify-content-between">
      <h4 class="font-lg mb-2xs">List item heading</h4>
      <small class="fg-subtle">3 days ago</small>
    </div>
    <p class="mb-2xs">Some placeholder content in a paragraph.</p>
    <small class="fg-subtle">And some muted small print.</small>
  </a>
  <a href="#" class="list-item list-action">
    <div class="d-flex w-100 justify-content-between">
      <h4 class="font-lg mb-2xs">List item heading</h4>
      <small class="fg-subtle">3 days ago</small>
    </div>
    <p class="mb-2xs">Some placeholder content in a paragraph.</p>
    <small class="fg-subtle">And some muted small print.</small>
  </a>
</div>

Form controls

Place checkboxes or radios inside list items for a selectable list. Each item holds a .check-input and its <label>.

Every control needs an accessible name. Without a visible label, add an aria-label attribute to the input.

HTML
<ul class="list">
  <li class="list-item">
    <input class="check-input me-xs" type="checkbox" value="" id="firstCheckbox">
    <label for="firstCheckbox">First checkbox</label>
  </li>
  <li class="list-item">
    <input class="check-input me-xs" type="checkbox" value="" id="secondCheckbox">
    <label for="secondCheckbox">Second checkbox</label>
  </li>
  <li class="list-item">
    <input class="check-input me-xs" type="checkbox" value="" id="thirdCheckbox">
    <label for="thirdCheckbox">Third checkbox</label>
  </li>
</ul>

Stretched labels

Apply the .stretched-link class to the <label> to extend its clickable area over the entire list item, which gives a larger target on touch devices.

HTML
<ul class="list">
  <li class="list-item">
    <input class="check-input me-xs" type="checkbox" value="" id="firstCheckboxStretched">
    <label class="stretched-link" for="firstCheckboxStretched">First checkbox</label>
  </li>
  <li class="list-item">
    <input class="check-input me-xs" type="checkbox" value="" id="secondCheckboxStretched">
    <label class="stretched-link" for="secondCheckboxStretched">Second checkbox</label>
  </li>
  <li class="list-item">
    <input class="check-input me-xs" type="checkbox" value="" id="thirdCheckboxStretched">
    <label class="stretched-link" for="thirdCheckboxStretched">Third checkbox</label>
  </li>
</ul>

Context variants

Context classes give a list, or single items, the colors of a context. Apply .context.{name} to a .list-item to mark its state, importance or category.

  • A simple default list item
  • A simple alternate list item
  • A simple primary list item
  • A simple secondary list item
  • A simple neutral list item
  • A simple danger list item
  • A simple success list item
  • A simple warning list item
  • A simple info list item
  • A simple black list item
  • A simple white list item
HTML
<ul class="list">
  <li class="list-item context default">A simple default list item</li>
  <li class="list-item context alternate">A simple alternate list item</li>
  <li class="list-item context primary">A simple primary list item</li>
  <li class="list-item context secondary">A simple secondary list item</li>
  <li class="list-item context neutral">A simple neutral list item</li>
  <li class="list-item context danger">A simple danger list item</li>
  <li class="list-item context success">A simple success list item</li>
  <li class="list-item context warning">A simple warning list item</li>
  <li class="list-item context info">A simple info list item</li>
  <li class="list-item context black">A simple black list item</li>
  <li class="list-item context white">A simple white list item</li>
</ul>

Interactive items

Combine a context class with .list-action for actionable items in a context color: the hover, pressed and active states use the colors of the item's context. Apply .active to mark the selected item.

HTML
<div class="list list-action">
  <a href="#" class="list-item context default">A simple default list action</a>
  <a href="#" class="list-item context alternate">A simple alternate list action</a>
  <a href="#" class="list-item context primary">A simple primary list action</a>
  <a href="#" class="list-item context secondary">A simple secondary list action</a>
  <a href="#" class="list-item context neutral">A simple neutral list action</a>
  <a href="#" class="list-item context danger">A simple danger list action</a>
  <a href="#" class="list-item context success">A simple success list action</a>
  <a href="#" class="list-item context warning">A simple warning list action</a>
  <a href="#" class="list-item context info">A simple info list action</a>
  <a href="#" class="list-item context black">A simple black list action</a>
  <a href="#" class="list-item context white">A simple white list action</a>
</div>

Accessibility tip: Color alone shouldn't convey meaning as it's not perceived by assistive technology users. Ensure clarity through text with adequate contrast, ARIA attributes where needed, and consider using .visually-hidden for screen reader content.

Context styles

A context class on the .list element colors the whole list, and the .solid, .smooth and .outline classes next to it select how: each sets the background, border and text colors of the context in its own style.

  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
  • An item
  • A second item
  • A third item
  • A fourth item
  • And a fifth one
HTML
<div class="grid grid-cols-1 md:grid-cols-2 gap-lg">
  <div>
    <ul class="list context primary">
      <li class="list-item">An item</li>
      <li class="list-item">A second item</li>
      <li class="list-item">A third item</li>
      <li class="list-item">A fourth item</li>
      <li class="list-item">And a fifth one</li>
    </ul>
  </div>
  <div>
    <ul class="list context primary solid flush rounded">
      <li class="list-item">An item</li>
      <li class="list-item">A second item</li>
      <li class="list-item">A third item</li>
      <li class="list-item">A fourth item</li>
      <li class="list-item">And a fifth one</li>
    </ul>
  </div>
  <div>
    <ul class="list context primary smooth flush rounded">
      <li class="list-item">An item</li>
      <li class="list-item">A second item</li>
      <li class="list-item">A third item</li>
      <li class="list-item">A fourth item</li>
      <li class="list-item">And a fifth one</li>
    </ul>
  </div>
  <div>
    <ul class="list context primary outline">
      <li class="list-item">An item</li>
      <li class="list-item">A second item</li>
      <li class="list-item">A third item</li>
      <li class="list-item">A fourth item</li>
      <li class="list-item">And a fifth one</li>
    </ul>
  </div>
</div>

JavaScript API

Lists have no plugin of their own. The Tab plugin turns a list of actionable items into the navigation of tabbed content. Chassis JS ships as an ES module — import the Tab class:

JavaScript
import { Tab } from '@chassis-ui/css'

Tabbed navigation

Each list item is a tab that shows its .tab-pane and takes the .active class, so the list keeps its appearance while it controls which pane is visible.

HTML
<div class="grid">
  <div class="col-span-4">
    <div class="list" id="list-tab" role="tablist">
      <a class="list-item list-action active" id="list-home-item" data-cx-toggle="tab" href="#list-home" role="tab" aria-controls="list-home">Home</a>
      <a class="list-item list-action" id="list-profile-item" data-cx-toggle="tab" href="#list-profile" role="tab" aria-controls="list-profile">Profile</a>
      <a class="list-item list-action" id="list-messages-item" data-cx-toggle="tab" href="#list-messages" role="tab" aria-controls="list-messages">Messages</a>
      <a class="list-item list-action" id="list-settings-item" data-cx-toggle="tab" href="#list-settings" role="tab" aria-controls="list-settings">Settings</a>
    </div>
  </div>
  <div class="col-span-8">
    <div class="tab-content" id="nav-tabContent">
      <div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-item">...</div>
      <div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-item">...</div>
      <div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-item">...</div>
      <div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-item">...</div>
    </div>
  </div>
</div>

Triggers

The data-attribute API needs no JavaScript on the page beyond the plugin. Add data-cx-toggle="tab" to each list item, and point its href (or data-cx-target on a button) at the id of a .tab-pane.

HTML
<div role="tabpanel">
  <!-- List -->
  <div class="list" id="myList" role="tablist">
    <a class="list-item list-action active" data-cx-toggle="tab" href="#home" role="tab">Home</a>
    <a class="list-item list-action" data-cx-toggle="tab" href="#profile" role="tab">Profile</a>
    <a class="list-item list-action" data-cx-toggle="tab" href="#messages" role="tab">Messages</a>
    <a class="list-item list-action" data-cx-toggle="tab" href="#settings" role="tab">Settings</a>
  </div>

  <!-- Tab panes -->
  <div class="tab-content">
    <div class="tab-pane active" id="home" role="tabpanel">...</div>
    <div class="tab-pane" id="profile" role="tabpanel">...</div>
    <div class="tab-pane" id="messages" role="tabpanel">...</div>
    <div class="tab-pane" id="settings" role="tabpanel">...</div>
  </div>
</div>

The Tab documentation covers programmatic initialization, methods and events.

CSS

This component can be customized through Sass variables at compile time.

Custom properties

This component exposes CSS custom properties to control its appearance at runtime.

--padding-y: var(--list-padding-y, #{$list-padding-y});
--padding-x: var(--list-padding-x, #{$list-padding-x});
--fg-color: var(--list-fg-color, #{$list-fg-color});
--bg-color: var(--list-bg-color, #{$list-bg-color});
--border-color: var(--list-border-color, #{$list-border-color});
--border-width: var(--list-border-width, #{$list-border-width});
--border-radius: var(--list-border-radius, #{$list-border-radius});
--item-fg-disabled: var(--list-fg-disabled, #{$list-disabled-fg-color});
--item-bg-disabled: var(--list-bg-disabled, #{$list-disabled-bg-color});
--item-fg-active: var(--list-fg-active, #{$list-active-fg-color});
--item-bg-active: var(--list-bg-active, #{$list-active-bg-color});
--item-border-active: var(--list-active-border-color, #{$list-active-border-color});

Sass variables

This component uses Sass variables in scss/config/_defaults.scss to define its defaults.

$list-padding-y:              var(--space-xs);
$list-padding-x:              var(--space-md);
$list-fg-color:               var(--fg-main);
$list-bg-color:               var(--bg-main);
$list-border-color:           var(--border-subtle);
$list-border-width:           var(--border-width-md);
$list-border-radius:          var(--border-radius-md);
$list-active-fg-color:        var(--fg-active);
$list-active-bg-color:        var(--bg-active);
$list-active-border-color:    transparent;
$list-disabled-fg-color:      var(--fg-slight);
$list-disabled-bg-color:      transparent;

Placeholder selector

Actionable list items extend the %interactive placeholder selector, which holds the hover, focus, pressed and disabled states shared with menu items and navigation links.

%interactive {

  width: 100%; // For `<button>`s (anchors become 100% by default though)
  text-align: inherit; // For `<button>`s (anchors inherit)

  &:hover,
  &:focus {
    --bg-color: var(--bg-even);
    z-index: 1; // Place hover/focus items above their siblings for proper border styling
    text-decoration: none;
  }

  &:focus-visible {
    @include focus-ring(true);
  }

  &:active {
    --bg-color: var(--bg-evident);
  }

  &:disabled,
  &.disabled {
    --fg-color: var(--fg-slight);
    pointer-events: none;
  }

  &:visited {
    color: var(--fg-color);
  }

}