<cs-badge>
StableFeedbackSince 0.1

Badges draw attention to adjacent content by displaying a status, count, or label. Use them to highlight notifications, categorize items, or flag new activity.

New
Featured

Examples

Variant

Set the variant attribute to change the badge’s variant.

Brand Neutral Highlight Information Success Warning Danger

Appearance

Use the appearance attribute to change the badge’s visual appearance.

Accent Filled-Outlined Filled Outlined
Accent Filled-Outlined Filled Outlined
Accent Filled-Outlined Filled Outlined
Accent Filled-Outlined Filled Outlined
Accent Filled-Outlined Filled Outlined
Accent Filled-Outlined Filled Outlined
Accent Filled-Outlined Filled Outlined

Size

Badges are sized relative to the current font size. You can set font-size on any badge (or an ancestor element) to change it.

Extra Small Small Medium Large Extra Large

Pill

Use the pill attribute to give badges rounded edges.

Brand Neutral Highlight Information Success Warning Danger

Drawing Attention

Use the attention attribute to draw attention to the badge with a subtle animation. Supported effects are bounce, pulse and none.

1 1 1 1 1 1 1
1 1 1 1 1 1 1

Set the --cs-badge-pulse-color custom property to color the pulse independently of the badge’s variant.

1

Start & End Decorations

Use the start and end slots to add presentational elements like <cs-icon> alongside the badge’s label.

Start End Both

With Buttons

One of the most common use cases for badges is attaching them to buttons. To make this easier, badges will be automatically positioned at the top-right when they’re a child of a button.

Requests 30 Warnings 8 Errors 6

The badge’s text is part of the accessible name of the button, link or other control it is in, so the first button is named “Requests 30”. WebKit leaves out the space and names it “Requests30”, a known gap. An icon button has no text to say what its count means, so follow Icon Button With a Badge instead.

Accessibility Considerations

A badge is not a live region, so a screen reader does not announce a change to its text. If people need to hear about a change, announce it as well. That goes for a count that changes because of something the user did, such as adding an item to a cart, and for one that changes on its own, such as a new message arriving. Keep an empty <div class="cs-visually-hidden" role="status"></div> on the page, outside the button or other control the badge is in, and set its text to the new count with context, such as “3 items in cart”.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/badge/badge.js';
import './cornerstone/components/badge/badge.js';
import CsBadge from '@cruglobal/cornerstone-components/react/badge/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The badge's content.
endAn element, such as <cs-icon>, placed after the label.
startAn element, such as <cs-icon>, placed before the label.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
appearanceappearanceThe badge's visual appearance.'accent' | 'filled' | 'outlined' | 'filled-outlined''accent'Yes
attentionattentionAdds an animation to draw attention to the badge.'none' | 'pulse' | 'bounce''none'Yes
pillpillDraws a pill-style badge with rounded edges.booleanfalseYes
variantvariantThe badge's theme variant. Defaults to brand if not within another element with a variant.'brand' | 'neutral' | 'highlight' | 'information' | 'success' | 'warning' | 'danger''brand'Yes

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--cs-badge-pulse-colorThe color of the badge's pulse effect when using attention="pulse". Defaults to the badge's outer color for its appearance: the fill for accent and filled, the border for outlined and filled-outlined.—

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
badgeThe component's outer wrapper.::part(badge)
endThe container that wraps the end slot.::part(end)
startThe container that wraps the start slot.::part(start)