Tags
Documentation and examples for the Tags component, our small component for labeling and categorizing content.
Examples
Tags scale to match the size of the immediate parent element by using relative font sizing and em
units.
Simple list
<ul class="tag-list">
<li class="tag">Tag 01</li>
<li class="tag">Tag 02</li>
<li class="tag">Tag 03</li>
<li class="tag">Another tag</li>
<li class="tag">…</li>
</ul>
Icon list
<ul class="tag-list">
<li class="tag"><span class="tag-icon"><svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#check-lg"/>
</svg>
</span>Tag 01</li>
<li class="tag"><span class="tag-icon"><svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#check-lg"/>
</svg>
</span>Tag 02</li>
<li class="tag"><span class="tag-icon"><svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#check-lg"/>
</svg>
</span>Tag 03</li>
<li class="tag"><span class="tag-icon"><svg class="of-icon" width="32" height="32" fill="currentColor">
<use href="/assets/icons/bootstrap-icons.svg#check-lg"/>
</svg>
</span>Another tag</li>
</ul>
Background colors
Set a background-color
with contrasting foreground color
with our .text-bg-{color}
helpers. Previously it was required to manually pair your choice of .text-{color}
and .bg-{color}
utilities for styling, which you still may use if you prefer.
<ul class="tag-list">
<li class="tag text-bg-primary">Primary</li>
<li class="tag text-bg-secondary">Secondary</li>
<li class="tag text-bg-success">Success</li>
<li class="tag text-bg-danger">Danger</li>
<li class="tag text-bg-warning">Warning</li>
<li class="tag text-bg-info">Info</li>
<li class="tag text-bg-light">Light</li>
<li class="tag text-bg-dark">Dark</li>
</ul>
Accessibility tip: Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies like screen readers. Please ensure the meaning is obvious from the content itself (e.g., the visible text with a sufficient color contrast) or is included through alternative means, such as additional text hidden with the
.visually-hidden
class.
CSS
Variables
Tags use local CSS variables on .tag
for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
--#{$prefix}tag-padding-x: #{$tag-padding-x};
--#{$prefix}tag-padding-y: #{$tag-padding-y};
@include rfs($tag-font-size, --#{$prefix}tag-font-size);
--#{$prefix}tag-font-weight: #{$tag-font-weight};
--#{$prefix}tag-color: #{$tag-color};
--#{$prefix}tag-bg: #{$tag-bg};
--#{$prefix}tag-border-radius: #{$tag-border-radius};
--#{$prefix}tag-icon-font-size: #{$tag-icon-font-size};
--#{$prefix}tag-icon-space-x: #{$tag-icon-space-x};
Sass variables
Tag list
$tag-list-gap-x: .5em;
$tag-list-gap-y: .5em;
Tag
$tag-font-size: .875em;
$tag-font-weight: null;
$tag-color: var(--#{$prefix}dark);
$tag-bg: var(--#{$prefix}gray-100);
$tag-padding-y: .35em;
$tag-padding-x: .65em;
$tag-border-radius: var(--#{$prefix}border-radius);
$tag-icon-font-size: 1.5em;
$tag-icon-space-x: .1em;