Skip to main content

What are you looking for?

Try searching for…

Components

Badge

Badge is a non-interactive component that displays status with or without a number. Use tag if you want text instead of a number.

HTML

Press Enter to start editing
Unable to parse html
const Preview = () => {
  return <Badge count={15} maxCount={9} />;
};

render(<Preview />)

Usage

Badge renders its text with CSS in a :before pseudo-element on a span tag. You use the class name ds-badge, in conjunction with the data attribute data-count.

CSS variables and data attributes

Sizes are controlled with data-size and colors with data-color. The component will inherit from the nearest parent with these set.

Data Attributes
NameValue
data-variantbase, tinted
data-placementtop-right, top-left, bottom-right, bottom-left
data-overlapcircle
CSS Variables
NameValue
--dsc-badge-backgroundvar(--ds-color-base-default)
--dsc-badge-colorvar(--ds-color-base-contrast-default)
--dsc-badge-padding0 calc(var(--ds-size-1) + var(--ds-size-1)/2)
--dsc-badge-sizecalc(var(--ds-size-3) + var(--ds-size-1)/2)
--dsc-badge-topinherit
--dsc-badge-bottominherit
--dsc-badge-leftinherit
--dsc-badge-rightinherit

Examples

Floating

Not all icons have the same shape, and you may have to change where the badge should be placed.

If you want it to be floating, the class ds-badge--position must be used on a wrapper around the element that the badge is to be placed over. data-placement is used on the wrapper to determine the placement. See the “CSS variables and data attributes” section above for supported placements.

If you are placing the badge on a circular element, you can use data-overlap="circle" to get circular overlap.

Custom placement

If you can't get the badge to be where you want it, you can use the variables --dsc-badge-top|right|bottom|left to override the placement.

This also works when using data-overlap="circle".

React

count
Description

The number to display in the badge

Type
number
maxCount
Description

The maximum number to display in the badge, when the count exceeds this number, the badge will display `{max}+`

Type
number
variant
Description

Change the background color of the badge.

Type
"base" | "tinted"
Default
base
NameTypeDefaultDescription
countnumber-

The number to display in the badge

maxCountnumber-

The maximum number to display in the badge, when the count exceeds this number, the badge will display `{max}+`

variant"base" | "tinted"base

Change the background color of the badge.

BadgePosition

placement
Description

The placement of the badge

Type
"top-right" | "top-left" | "bottom-right" | "bottom-left"
Default
top-right
overlap
Description

Use when badge is floating to change the position of the badge

Type
"circle" | "rectangle"
Default
rectangle
NameTypeDefaultDescription
placement"top-right" | "top-left" | "bottom-right" | "bottom-left"top-right

The placement of the badge

overlap"circle" | "rectangle"rectangle

Use when badge is floating to change the position of the badge

Edit this page on github.com (opens in a new tab)