Label content with badges for counts, indicators, and status markers, in solid, outline, and smooth styles and three sizes.
Introduction
Badges are small inline labels that add a count, a tag, or a status indicator to content. They highlight new items, display notification counts, and sit inside other components such as buttons and avatars. A badge takes its color from a context class and comes in three styles and three sizes.
Basic structure
Add the .badge class to an element to render it as a badge. Without a context class the badge takes the colors of the context around it, and the .circle modifier gives it equal width and height for a short count.
<!-- Base class -->
<span class="badge">Base</span>
<span class="badge">24</span>
<span class="badge circle">24</span>
<!-- Default variant -->
<span class="badge default">Default</span>
<span class="badge default">24</span>
<span class="badge default circle">24</span>
<!-- Primary variant -->
<span class="badge primary">Primary</span>
<span class="badge primary">24</span>
<span class="badge primary circle">24</span>Badge elements
The .badge class works on any inline or block element, links included, and always renders as an inline flex box.
<span class="badge primary">Span</span>
<a class="badge primary" href="#">Link</a>
<div class="badge primary">Div</div>Color variants
The default badge style is solid: the background color of the context with contrasting text. Add a context color class, such as .primary or .secondary, next to .badge to choose the context.
<span class="badge default">Default</span>
<span class="badge alternate">Alternate</span>
<span class="badge primary">Primary</span>
<span class="badge secondary">Secondary</span>
<span class="badge neutral">Neutral</span>
<span class="badge danger">Danger</span>
<span class="badge success">Success</span>
<span class="badge warning">Warning</span>
<span class="badge info">Info</span>
<span class="badge black">Black</span>
<span class="badge white">White</span>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.
Outline style
Add the .outline class for a badge with a transparent background and a border and text in the context color.
<span class="badge default outline">Default</span>
<span class="badge alternate outline">Alternate</span>
<span class="badge primary outline">Primary</span>
<span class="badge secondary outline">Secondary</span>
<span class="badge neutral outline">Neutral</span>
<span class="badge danger outline">Danger</span>
<span class="badge success outline">Success</span>
<span class="badge warning outline">Warning</span>
<span class="badge info outline">Info</span>
<span class="badge black outline">Black</span>
<span class="badge white outline">White</span>Smooth style
Add the .smooth class for a badge with a subdued background of the context color and matching text.
<span class="badge default smooth">Default</span>
<span class="badge alternate smooth">Alternate</span>
<span class="badge primary smooth">Primary</span>
<span class="badge secondary smooth">Secondary</span>
<span class="badge neutral smooth">Neutral</span>
<span class="badge danger smooth">Danger</span>
<span class="badge success smooth">Success</span>
<span class="badge warning smooth">Warning</span>
<span class="badge info smooth">Info</span>
<span class="badge black smooth">Black</span>
<span class="badge white smooth">White</span>Size variants
Badges come in three sizes. The .sm and .lg classes change the paddings, the font size, the radius and the icon size; the medium size needs no class.
<span class="badge sm primary">Small</span>
<span class="badge primary">Medium</span>
<span class="badge lg primary">Large</span>
<span class="badge sm circle primary">2</span>
<span class="badge circle primary">2</span>
<span class="badge lg circle primary">2</span>Icons
A badge can hold an icon before or after its text, either an SVG icon or an icon font. The icon takes the icon size of the badge size.
<span class="badge default sm">
<svg class="icon" aria-hidden="true"><use href="#info-circle-solid"></use></svg>
<span>Small</span>
</span>
<span class="badge default">
<svg class="icon" aria-hidden="true"><use href="#info-circle-solid"></use></svg>
<span>Medium</span>
</span>
<span class="badge default lg">
<svg class="icon" aria-hidden="true"><use href="#info-circle-solid"></use></svg>
<span>Large</span>
</span>
<span class="badge primary sm">
<span>Small</span>
<span class="icon cx-info-circle-solid" aria-hidden="true"></span>
</span>
<span class="badge primary">
<span>Medium</span>
<span class="icon cx-info-circle-solid" aria-hidden="true"></span>
</span>
<span class="badge primary lg">
<span>Large</span>
<span class="icon cx-info-circle-solid" aria-hidden="true"></span>
</span>The spacing of an icon comes from the :first-child and :last-child selectors. Wrap the badge text in a <span> element so that the icon is matched as the first or last child.
Use cases
Badges combine with other components and with utilities for counters, notification indicators and custom shapes.
With components
Place a badge inside a button or another component to show a count or a status next to its label.
<button type="button" class="button primary">
Notifications
<span class="badge secondary circle" role="status"
aria-label="new notifications">2</span>
</button>Unless the surrounding content makes the meaning of a badge clear, add visually hidden text that explains it.
A bare number or dot gives screen reader users no context. Add role="status" to a counter that updates, so that changes are announced, and role="presentation" to a decorative badge. Explain the meaning of a badge with aria-label or with a <span class="visually-hidden"> inside it.
Positioned badges
The position utilities place a badge on the corner of an element, as a notification indicator.
<button type="button" class="button primary position-relative">
Inbox
<span class="badge secondary position-absolute top-0 start-100 translate-middle">
99+ <span class="visually-hidden">unread messages</span>
</span>
</button>A badge with only visually hidden text and a padding utility renders as an indicator dot.
<button type="button" class="button primary position-relative">
Profile
<span class="badge secondary p-xs rounded-full
position-absolute top-0 start-100 translate-middle">
<span class="visually-hidden">New alerts</span>
</span>
</button>Custom corners
The border-radius utilities override the default radius of a badge, from square corners to a pill, while the paddings and the typography stay the same.
<span class="badge primary rounded-zero">Sharp</span>
<span class="badge primary rounded-sm">Blunt</span>
<span class="badge primary rounded-md">Soft</span>
<span class="badge primary rounded-full">Pill</span>Adaptive sizing
The .badge-adaptive class sizes a badge in em units, so its font size, paddings and icon size follow the font size of the parent element. The same badge then fits headings and body text of any size, while a badge with a size class keeps its fixed size.
Example heading Adaptive Large
Extra small paragraph Adaptive Small
<h3>
Example heading
<span class="badge primary badge-adaptive">Adaptive</span>
<span class="badge primary lg">Large</span>
</h3>
<hr>
<p class="font-xs">
Extra small paragraph
<span class="badge primary badge-adaptive">Adaptive</span>
<span class="badge primary sm">Small</span>
</p>With wrappers
Add .badge-adaptive to a wrapper to give every badge inside it adaptive sizing.
Example heading New
Example heading New
Example heading New
Example heading New
Example heading New
Example heading New
<div class="badge-adaptive">
<h1>Example heading <span class="badge primary">New</span></h1>
<h2>Example heading <span class="badge primary">New</span></h2>
<h3>Example heading <span class="badge primary">New</span></h3>
<h4>Example heading <span class="badge primary">New</span></h4>
<h5>Example heading <span class="badge primary">New</span></h5>
<h6>Example heading <span class="badge primary">New</span></h6>
</div>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.
--size: var(--badge-size, #{$badge-medium-size});
--padding-y: var(--badge-padding-y, #{$badge-medium-padding-y});
--padding-x: var(--badge-padding-x, #{$badge-medium-padding-x + $badge-medium-nudge});
--gap: var(--badge-gap, #{$badge-medium-gap});
--nudge: var(--badge-nudge, #{$badge-medium-nudge});
--border-width: var(--badge-border-width, #{$badge-border-width});
--border-color: var(--badge-border-color, transparent);
--border-radius: var(--badge-border-radius, #{$badge-medium-border-radius});
--icon-size: var(--badge-icon-size, #{$badge-medium-icon-size});
@include map-font($badge-medium-font, badge); // e.g. --[property-name]: var(--badge-[propery-name], [value]);Design tokens
This component consumes design tokens from Chassis Tokens with the $cx- prefix. — See the design tokens page.
$badge-medium-font: $cx-font-badge-medium;
$badge-medium-size: $cx-size-badge-medium-main;
$badge-medium-icon-size: $cx-size-badge-medium-icon;
$badge-medium-padding-y: $cx-space-badge-medium-padding-y;
$badge-medium-padding-x: $cx-space-badge-medium-padding-x;
$badge-medium-gap: $cx-space-badge-medium-gap;
$badge-medium-nudge: $cx-space-badge-medium-nudge;
$badge-medium-border-radius: $cx-border-radius-badge-medium;
$badge-large-font: $cx-font-badge-large;
$badge-large-size: $cx-size-badge-large-main;
$badge-large-icon-size: $cx-size-badge-large-icon;
$badge-large-padding-y: $cx-space-badge-large-padding-y;
$badge-large-padding-x: $cx-space-badge-large-padding-x;
$badge-large-gap: $cx-space-badge-large-gap;
$badge-large-nudge: $cx-space-badge-large-nudge;
$badge-large-border-radius: $cx-border-radius-badge-large;
$badge-small-font: $cx-font-badge-small;
$badge-small-size: $cx-size-badge-small-main;
$badge-small-icon-size: $cx-size-badge-small-icon;
$badge-small-padding-y: $cx-space-badge-small-padding-y;
$badge-small-padding-x: $cx-space-badge-small-padding-x;
$badge-small-gap: $cx-space-badge-small-gap;
$badge-small-nudge: $cx-space-badge-small-nudge;
$badge-small-border-radius: $cx-border-radius-badge-small;
$badge-border-width: $cx-border-width-badge-main;