PeakUI

Badge

A small indicator anchored over another element, such as a count or a status dot

Usage

import {Badge} from "@peakui/react";

Anatomy

import {Badge} from "@peakui/react";

export default () => (
  <Badge.Anchor>
    {/* the element the badge sits over */}
    <Badge>
      <Badge.Label>5</Badge.Label>
    </Badge>
  </Badge.Anchor>
);

A string or a number passed as children is wrapped in Badge.Label for you.

Badge or Chip

Badge is positioned over a sibling inside Badge.Anchor: an avatar with a count, an icon with a dot. Chip is an inline label that takes its own place in the flow.

Accessibility

A badge has no role and is not announced when it changes, so its meaning belongs in the accessible name of the element it sits over, as in aria-label="Inbox, 5 unread". The badge renders a plain <span>, so aria-label on the badge itself is prohibited and assistive technology ignores it; an icon inside a badge carries its own name through role="img".

Examples

Placements

The names are physical: top-right is the top right corner in every writing direction.

Colors

Variants

Sizes

Dot

A badge without children is a dot.

With Content

Text wider than the badge's height renders as a rounded rectangle; a single character stays a circle.

On a Button

Customization

Tailwind CSS

Global CSS

@layer components {
  .badge {
    --badge-border: var(--color-surface);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Badge component uses these CSS classes (view source styles):

Base & Element Classes

  • .badge-anchor - The wrapper the badge is positioned against
  • .badge - The indicator
  • .badge__label - The text inside it

Size Classes

  • .badge--sm, .badge--md (default), .badge--lg

Color Classes

  • .badge--default, .badge--accent, .badge--success, .badge--warning, .badge--danger

Variant Classes

  • .badge--primary (default), .badge--secondary, .badge--soft

Placement Classes

  • .badge--top-right (default), .badge--top-left, .badge--bottom-right, .badge--bottom-left

Slots

  • [data-slot="badge-anchor"]
  • [data-slot="badge"]
  • [data-slot="badge-label"]

CSS Variables

VariablePurpose
--badge-bgFill, set by the variant and color classes
--badge-fgText color
--badge-borderThe ring that separates the badge from what it covers; the page background by default

API Reference

Badge

PropTypeDefaultDescription
color'default' | 'accent' | 'success' | 'warning' | 'danger''default'Color role
variant'primary' | 'secondary' | 'soft''primary'Fill style
size'sm' | 'md' | 'lg''md'Size
placement'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''top-right'Corner of the anchor
childrenReactNode-A string or number is wrapped in Badge.Label; omit it for a dot
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restEvery <span> attribute is accepted

Badge.Anchor

PropTypeDefaultDescription
childrenReactNode-The element the badge sits over, and the badge
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restEvery <span> attribute is accepted

Badge.Label

PropTypeDefaultDescription
childrenReactNode-The text
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restEvery <span> attribute is accepted

On this page