Skip to main content

Badge

Result
Loading...
Live Editor
<Badge>Badge</Badge>

Appearance

Result
Loading...
Live Editor
const appearances = ["solid", "faded", "outline", "ghost", "text"];

render(
  <div style={{ display: "flex", alignItems: "center", gap: "10px" }}>
    {appearances.map((appearance) => (
      <Badge key={appearance} appearance={appearance}>
        {appearance}
      </Badge>
    ))}
  </div>
);

Variant

Result
Loading...
Live Editor
const variants = [
  "primary",
  "secondary",
  "neutral",
  "danger",
  "warning",
  "success",
  "dark",
  "light",
];

render(
  <div style={{ display: "flex", gap: "10px", flexWrap: "wrap" }}>
    {variants.map((variant) => (
      <Badge key={variant} variant={variant}>
        {variant}
      </Badge>
    ))}
  </div>
);

Size

Result
Loading...
Live Editor
const sizes = ["xs", "sm", "md", "lg", "xl", "2xl", "3xl"];

render(
  <div style={{ display: "flex", alignItems: "center", gap: "10px" }}>
    {sizes.map((size) => (
      <Badge key={size} size={size}>
        {size}
      </Badge>
    ))}
  </div>
);

Shape

Result
Loading...
Live Editor
const shapes = ["rounded", "circular", "square"];

render(
  <div style={{ display: "flex", alignItems: "center", gap: "10px" }}>
    {shapes.map((shape) => (
      <Badge key={shape} shape={shape}>
        {shape}
      </Badge>
    ))}
  </div>
);

Fixed Ratio

When just using icons, you can set the fixedRatio prop to make sure the badge's width and height are equal.

Result
Loading...
Live Editor
<div style={{ display: "flex", gap: "10px", alignItems: "center" }}>
  <Badge shape="circular" variant="success" fixedRatio>
    <IconCheck />
  </Badge>
  <Badge shape="rounded" fixedRatio>
    <IconBell />
  </Badge>
  <Badge shape="square" variant="warning" fixedRatio>
    <IconClock />
  </Badge>
</div>

Dots

When no content is provided, the badge renders as just a shape with color.

Result
Loading...
Live Editor
<div style={{ display: "flex", alignItems: "center", gap: "10px" }}>
  <Badge shape="circular" variant="success" />
  <Badge shape="rounded" />
  <Badge shape="square" variant="warning" />
</div>

Slots

Content can be added to the start and end of the badge using the slotStart and slotEnd props.

Result
Loading...
Live Editor
// Icons from https://tabler.io/docs/icons/react
<div style={{ display: "flex", gap: "10px" }}>
  <Badge slotEnd={<IconArrowRight size={20} />}>With icon</Badge>
  <Badge slotStart="😀">With Emoji</Badge>
  <Badge slotStart="'Slot Start'" slotEnd="'Slot End'">
    With Text
  </Badge>
</div>

Numbers and Counters

Setting the isNumeric prop adds negative left/right margin to the children so the Badge is more circular when there is a single digit.

Result
Loading...
Live Editor
<div style={{ display: "flex", gap: "10px", alignItems: "center" }}>
  <Badge isNumeric>5</Badge>
  <Badge variant="danger" isNumeric>
    99+
  </Badge>
  <Badge variant="success" isNumeric>
    12
  </Badge>
  <Badge variant="warning" isNumeric>
    1
  </Badge>
  <Badge variant="dark" isNumeric>
    100
  </Badge>
  <Badge variant="light" isNumeric>
    1,100
  </Badge>
</div>

Positioning

Badges can be absolutely positioned relative to their parent container using the position prop.

Result
Loading...
Live Editor
const positions = [
  "top",
  "top-right",
  "right",
  "bottom-right",
  "bottom",
  "bottom-left",
  "left",
  "top-left",
];

render(
  <div style={{ display: "flex", gap: "30px", alignItems: "center" }}>
    {positions.map((position) => (
      <Button key={position}>
        Button
        <Badge position={position} variant="danger" fixedRatio size="sm">
          3
        </Badge>
      </Button>
    ))}
  </div>
);

You can also use the --inset suffix to position the badge further inside the corner of the parent. This can be helpful when the parent has rounded corners.

Result
Loading...
Live Editor
const positions = [
  "top-right--inset",
  "bottom-right--inset",
  "bottom-left--inset",
  "top-left--inset",
];

render(
  <div style={{ display: "flex", gap: "30px", alignItems: "center" }}>
    {positions.map((position) => (
      <Button key={position} shape="circular">
        Button
        <Badge position={position} variant="danger" fixedRatio size="sm">
          3
        </Badge>
      </Button>
    ))}
  </div>
);

Show Outline

The showOutline prop adds a white outline to help it visually cut into the shape it is over. The color of the outline can be customized with the --tipTop-Badge--showOutline__boxShadow CSS variable.

Result
Loading...
Live Editor
<div style={{ display: "flex", gap: "10px", alignItems: "center" }}>
  <Button>
    Button
    <Badge
      position="top-right--inset"
      variant="success"
      isNumeric
      size="sm"
      showOutline
    >
      3
    </Badge>
  </Button>
  <Button shape="circular">
    Button
    <Badge position="top-right--inset" variant="danger" size="xs" showOutline />
  </Button>
</div>

Props

CSS Variables

Root

VariableValue
--tipTop-Badge__borderWidth1px
--tipTop-Badge__borderRadiusvar(--tipTop__borderRadius--normal)
--tipTop-Badge__fontSizevar(--tipTop__fontSize--sm)
--tipTop-Badge__fontWeightvar(--tipTop__fontWeight--medium)
--tipTop-Badge__lineHeight1
--tipTop-Badge__minHeight1.25rem
--tipTop-Badge__minWidth1.25rem
--tipTop-Badge__paddingBlockvar(--tipTop__space--1)
--tipTop-Badge__paddingInlinevar(--tipTop__space--2)
--tipTop-Badge__displayinline-flex
--tipTop-Badge__alignItemscenter
--tipTop-Badge__justifyContentcenter
--tipTop-Badge__gapvar(--tipTop__space--1)
--tipTop-Badge__transitionbackground-color 0.15s ease-in-out, color 0.15s ease-in-out
--tipTop-Badge__textAligncenter
--tipTop-Badge__whiteSpacenowrap

Show Outline

VariableValue
--tipTop-Badge--showOutline__boxShadow0 0 0 2px #fff

Position

VariableValue
--tipTop-Badge--position__positionabsolute
--tipTop-Badge--position__zIndex10
--tipTop-Badge--position__transformtranslate(50%, -50%)

Variants

faded

change the background color

VariableValue
--tipTop-Badge--faded__bgColorMix-colorSpacesrgb
--tipTop-Badge--faded__bgColorMix-percent20%
--tipTop-Badge--faded__bgColorMix-blendColor#fff

Darken the text color over a faded background

VariableValue
--tipTop-Badge--faded__textColorMix-colorSpacesrgb
--tipTop-Badge--faded__textColorMix-percent65%
--tipTop-Badge--faded__textColorMix-blendColor#000

Slot

VariableValue
--tipTop-Badge-slot__displayinline-flex
--tipTop-Badge-slot__alignItemscenter
--tipTop-Badge-slot__justifyContentcenter

Slot Start

VariableValue
--tipTop-Badge-slotStart__marginInlineEndvar(--tipTop__space--1)

Slot End

VariableValue
--tipTop-Badge-slotEnd__marginInlineStartvar(--tipTop__space--1)

Children

VariableValue
--tipTop-Badge-children__displayinline-flex
--tipTop-Badge-children__alignItemscenter
--tipTop-Badge-children__justifyContentcenter