List groups
A basic set of list utilities for creating standalone list group components using standard HTML list types.
Examples
Both the .list-group
and .list-links
utilities are applied to single level (non-nested) unordered <ul>
, ordered <ol>
and definition <dl>
list types to convert them into component styles.
List groups
The .list-group
utility is applied to each list type, links included are treated as regular inline elements and multiple terms can be used with definition lists (see below).
- List item
- List item
- List item
- List item
- List item
- List item
- Term
- Description
- Description
Example HTML
<ul class="list-group">
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
<ol class="list-group">
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ol>
<dl class="list-group">
<dt>Term</dt>
<dd>Description</dd>
<dd>Description</dd>
</dl>
List links
The .list-links
turn single links within standard list types into block link elements with hover and focus styles. With the definition lists <dl>
the block links are only provided for the <dd>
content as shown below.
Example HTML
<ul class="list-links">
<li><a href="#">List item link</a></li>
<li><a href="#">List item link</a></li>
<li><a href="#">List item link</a></li>
</ul>
<ol class="list-links">
<li><a href="#">List item link</a></li>
<li><a href="#">List item link</a></li>
<li><a href="#">List item link</a></li>
</ol>
<dl class="list-links">
<dt>Term</dt>
<dd><a href="#">Description link</a></dd>
<dd><a href="#">Description link</a></dd>
</dl>
Multiple terms
Definition lists <dl>
can include multiple terms for both .list-group
and .list-links
utilities.
- Term
- Description
- Description
- Term
- Description
- Description
Example HTML
<dl class="list-group">
<dt>Term</dt>
<dd>Description</dd>
<dd>Description</dd>
<dt>Term</dt>
<dd>Description</dd>
<dd>Description</dd>
</dl>
<dl class="list-links">
<dt>Term</dt>
<dd><a href="#">Description link</a></dd>
<dd><a href="#">Description link</a></dd>
<dt>Term</dt>
<dd><a href="#">Description link</a></dd>
<dd><a href="#">Description link</a></dd>
</dl>
Using the module
Add the sassmods.scss
to your custom styles as below then include the Sass mixin anywhere below.
@use "sassmods/scss/sassmods" as *;
@include list-groups-css;
See customizing for information about using the Sass and CSS variables in the source code (see below) to customize the styles, and Sass variables (on the using SassMods page) for other ways to use the variables to create custom styles.
Source
_list-groups.scss
// ----------------------------------------------------------
// List groups
// ----------------------------------------------------------
$list-group-text-color: var(--list-group-text) !default;
$list-group-background-color: var(--list-group-bg) !default;
$list-group-link-color: var(--link, LinkText) !default;
$list-links-background-hover: var(--list-group-hover, color-mix(in srgb, CanvasText 3%, Canvas)) !default;
$list-group-padding-block: var(--list-group-py, 0.5rem) !default;
$list-group-padding-inline: var(--list-group-px, 0.75rem) !default;
$list-group-border-color: var(--list-group-bd-color, color-mix(in srgb, CanvasText 12%, Canvas)) !default;
$list-group-radius: var(--list-group-radius, 0.188rem) !default;
$list-group-inner-radius: calc(var(--list-group-radius, 0.188rem) - 1px) !default;
$list-group-dt-font-weight: var(--dt-fw) !default;
$list-group-dt-background-color: var(--list-group-dt-bg, color-mix(in srgb, CanvasText 5%, Canvas)) !default;
@mixin list-groups-css {
:where(.list-group, .list-links) {
--list-group-inner-radius: $list-group-inner-radius;
color: $list-group-text-color;
max-inline-size: var(--list-group-width);
border: 1px solid $list-group-border-color;
border-radius: $list-group-radius;
background-color: $list-group-background-color;
}
:where(.list-group, .list-links):is(ul, ol) {
list-style-type: "";
padding-inline-start: 0;
}
:where(.list-group, .list-links) dd {
margin-inline-start: 0;
}
:where(.list-group, .list-links) :is(li, dd):not(:last-child) {
border-block-end: 1px solid $list-group-border-color;
}
:where(.list-group :is(li, dt, dd), .list-links dt) {
padding-block: $list-group-padding-block;
padding-inline: $list-group-padding-inline;
}
:where(.list-group, .list-links) dt {
font-weight: $list-group-dt-font-weight;
border-block-end: 1px solid $list-group-border-color;
background-color: $list-group-dt-background-color;
}
:where(.list-group, .list-links) dt:first-child {
border-radius: var(--list-group-inner-radius) var(--list-group-inner-radius) 0 0;
}
// List links
:where(.list-links a) {
color: $list-group-link-color;
text-decoration: none;
display: block;
padding-block: $list-group-padding-block;
padding-inline: $list-group-padding-inline;
}
:where(.list-links a:is(:hover, :focus)) {
background-color: $list-links-background-hover;
}
:where(.list-links a:focus-visible) {
outline: none;
}
:where(.list-links *:first-child a:is(:hover, :focus)) {
border-radius: var(--list-group-inner-radius) var(--list-group-inner-radius) 0 0;
}
:where(.list-links *:last-child a:is(:hover, :focus)) {
border-radius: 0 0 var(--list-group-inner-radius) var(--list-group-inner-radius);
}
// Ordered lists, inserts counter-increment to replace list-style-type.
:where(.list-group, .list-links) ol {
counter-reset: ol-list;
}
:where(.list-group, .list-links):is(ol) li {
counter-increment: ol-list;
}
:where(.list-group):is(ol) li:before {
content: counter(ol-list) ". ";
margin-inline-end: 0.25rem;
}
:where(.list-links):is(ol) li a:before {
content: counter(ol-list) ". ";
margin-inline-end: 0.25rem;
}
}