Skip to content
All components
Primitives

Badge

Label an object with a short status, category or count that people scan rather than read.

Six colors across the four-step state scale.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add badge

Then import it from @/components/ui/badge. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Colors

Compare badge color roles with readable status labels. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeColors() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge>gray</Badge>
        <Badge color="blue">blue</Badge>
        <Badge color="green">green</Badge>
        <Badge color="orange">orange</Badge>
        <Badge color="red">red</Badge>
        <Badge color="purple">purple</Badge>
      </div>
    </div>
  )
}

Filled

Use filled badge emphasis for a strong visual treatment. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeFilled() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge color="blue" emphasis="filled">
          filled
        </Badge>
      </div>
    </div>
  )
}

Light

Compare the light badge treatment. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeLight() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge color="blue" emphasis="light">
          light
        </Badge>
      </div>
    </div>
  )
}

Lighter

Compare the lighter badge treatment. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeLighter() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge color="blue" emphasis="lighter">
          lighter
        </Badge>
      </div>
    </div>
  )
}

Stroke

Use a bordered badge treatment. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeStroke() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge color="blue" emphasis="stroke">
          stroke
        </Badge>
      </div>
    </div>
  )
}

Status with icon

Pair a status color with a decorative icon and a readable word. The text carries the meaning, so the status survives without color.

"use client"

import { AlertTriangleIcon, CheckIcon, ClockIcon } from "lucide-react"

import { Badge } from "@/components/ui/badge"

export function BadgeStatusWithIcon() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge color="green">
          <CheckIcon aria-hidden="true" />
          Paid
        </Badge>
        <Badge color="orange">
          <ClockIcon aria-hidden="true" />
          Pending
        </Badge>
        <Badge color="red">
          <AlertTriangleIcon aria-hidden="true" />
          Overdue
        </Badge>
      </div>
    </div>
  )
}

Count

Show a count next to the label it qualifies. Visually hidden text completes the number for screen reader users.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeCount() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex items-center gap-2 text-label-sm text-strong-950">
        <span>Inbox</span>
        <Badge color="blue" emphasis="filled">
          12<span className="sr-only"> unread messages</span>
        </Badge>
      </div>
    </div>
  )
}

Tag links

Render badges as real links through asChild. Each anchor keeps its href and link semantics; the badge only supplies appearance.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeTagLinks() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge asChild color="purple" emphasis="stroke">
          <a href="#design">Design</a>
        </Badge>
        <Badge asChild color="purple" emphasis="stroke">
          <a href="#research">Research</a>
        </Badge>
      </div>
    </div>
  )
}

Long label

Truncate a long badge label inside a narrow container. The full text stays in the DOM and in a title attribute.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeLongLabel() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="w-full max-w-60">
        <Badge className="max-w-full" title="Waiting for approval from the finance team">
          <span className="truncate">Waiting for approval from the finance team</span>
        </Badge>
      </div>
    </div>
  )
}

Dot

Lead a status label with a colored dot. dot adds a decorative dot in the badge's color role. The text still states the status.

"use client"

import { Badge } from "@/components/ui/badge"

export function BadgeDot() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge dot color="green">
          Active
        </Badge>
        <Badge dot color="orange">
          In review
        </Badge>
        <Badge dot color="red" emphasis="stroke">
          Failed
        </Badge>
        <Badge dot color="blue" emphasis="filled">
          Live
        </Badge>
        <Badge dot>Draft</Badge>
      </div>
    </div>
  )
}

With avatar

Show a person inside a badge with a small avatar. The avatar is hidden from assistive technology because the name is the badge text.

"use client"

import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"

export function BadgeWithAvatar() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge>
          <Avatar aria-hidden="true">
            <AvatarFallback className="text-[0.5625rem]">AR</AvatarFallback>
          </Avatar>
          Ana Ruiz
        </Badge>
        <Badge color="blue" emphasis="stroke">
          <Avatar aria-hidden="true">
            <AvatarFallback className="text-[0.5625rem]">BO</AvatarFallback>
          </Avatar>
          Ben Okafor
        </Badge>
      </div>
    </div>
  )
}

Removable

Remove filters with an accessible close button. onRemove renders a 24px remove button named by removeLabel. A reset action restores removed filters in this example.

"use client"

import * as React from "react"

import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"

const initialFilters = ["Design", "Engineering", "Marketing"]

export function BadgeRemovable() {
  const [filters, setFilters] = React.useState(initialFilters)

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-col gap-2">
        <div role="group" aria-label="Active filters" className="flex flex-wrap items-center gap-2">
          {filters.map((filter) => (
            <Badge
              key={filter}
              color="blue"
              onRemove={() => setFilters((current) => current.filter((value) => value !== filter))}
              removeLabel={`Remove ${filter} filter`}
            >
              {filter}
            </Badge>
          ))}
        </div>
        {filters.length < initialFilters.length && (
          <Button size="xs" emphasis="link" className="w-fit" onClick={() => setFilters(initialFilters)}>
            Reset filters
          </Button>
        )}
      </div>
    </div>
  )
}

Icon only

Show an icon-only badge with an accessible name. iconOnly makes the badge square; with aria-label it receives role="img" so the name is announced.

"use client"

import { AlertTriangleIcon, CheckIcon, StarIcon } from "lucide-react"

import { Badge } from "@/components/ui/badge"

export function BadgeIconOnly() {
  

  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap items-center gap-2">
        <Badge iconOnly color="green" aria-label="Verified">
          <CheckIcon aria-hidden="true" />
        </Badge>
        <Badge iconOnly color="blue" emphasis="filled" aria-label="Featured">
          <StarIcon aria-hidden="true" />
        </Badge>
        <Badge iconOnly color="red" emphasis="stroke" aria-label="Needs attention">
          <AlertTriangleIcon aria-hidden="true" />
        </Badge>
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Badge

Show a compact textual category, count, or status.

Badge props
PropTypeDefaultDescription
color"gray" | "blue" | "green" | "orange" | "red" | "purple" | undefined"gray"Semantic color role for the badge. Pair meaningful status colors with readable text; colors remain customizable.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
emphasis"filled" | "stroke" | "lighter" | "light" | null | undefined"lighter"Visual treatment: filled, light, lighter or stroke. It does not add status semantics by itself.
iconOnlyboolean | undefinedfalseSquare badge for a single icon. Provide aria-label (the badge then gets role="img") or visually hidden text, because there is no visible label. Defaults to false.
dotboolean | undefinedfalseShow a small decorative dot before the label in the badge's color role. The label must still state the meaning. Defaults to false.
removeLabelstring | undefined—Accessible name for the remove button. Defaults to "Remove <label>" for string labels, otherwise "Remove".
asChildboolean | undefinedfalseMerge this part's props and behavior into one child instead of rendering its default element. Preserve that child's semantics and required accessibility attributes.
Inherited props (13)
Badge inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/badge.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • A status attached to a record: 'Paid', 'Pending', 'Overdue' next to an invoice or in a table cell.
  • A category or tag on a card or list item, optionally rendered as a link to a filtered view through asChild.
  • A count next to the label it qualifies, such as unread messages beside a navigation item.

When not to use

  • Explaining a problem or telling people what to do next; a badge has room for a word, not a sentence.
  • Triggering an action; a badge is passive text unless asChild renders a real link.
  • Filters or tags that can be toggled or removed; those need button semantics and a pressed or remove state.

Anatomy

Badge
An inline span (or its single child with asChild) with a color role and an emphasis. Does not wrap: whitespace-nowrap and overflow-hidden (visible when removable). iconOnly makes it a 20px square; with aria-label it receives role="img".
Leading icon
Optional child SVG sized to 12px. Mark it aria-hidden when the text already states the status.
Dot
Rendered by dot: a decorative 6px dot before the label in the badge's color role (current text color on filled). Hidden from assistive technology.
Avatar
Optional leading Avatar child, resized to 16px. Hide it from assistive technology when the badge text names the person.
Remove button
Rendered by onRemove: a native button after the label with a 24px target, named by removeLabel (default "Remove <label>"). Not rendered with asChild.

Keyboard & interaction

  • A default badge is not focusable and has no interaction; it is read in place with the surrounding text.
  • With asChild and an anchor, the badge is a normal link: Tab focuses it, Enter follows href, and focus styling comes from the link.
  • There is no hover, pressed or selected state built in; adding one implies an interactive control that the component does not provide.
  • The remove button is a separate tab stop and calls onRemove on click, Enter or Space; the badge itself stays passive.

Responsive behavior

  • Badge text never wraps; keep labels to one or two words so a row of badges fits at 320 CSS pixels.
  • Put badges in a flex-wrap container so several badges move to the next line instead of overflowing.
  • For unavoidable long labels give the badge max-w-full, wrap the text in a truncating span and add the full text in title; screen readers still read the whole text.
  • Linked badges are small; when they are touch targets, leave enough space around them to meet the 24x24 target-size spacing exception (WCAG 2.5.8).

Content guidelines

  • One or two words in sentence case: 'In review', not 'IN REVIEW' or 'This item is currently in review'.
  • Use the same word for the same status everywhere in the product.
  • For counts, add visually hidden text with the unit ('unread messages'), and cap large numbers ('99+').
  • Map status colors consistently: green for done or healthy, orange for attention, red for failure, gray for neutral; the word still has to say it.
  • Removable badges name the action and the item: "Remove Design filter". After removal, move focus to a sensible neighbor or keep a way to restore the item.
  • Icon-only badges need aria-label (or visually hidden text) that states the meaning, such as Verified.

Alternatives

  • Alert — A status that needs an explanation or a next step.
  • Toggle group — Selectable filter chips with a real pressed state.
  • Button — An action, including a small removable-tag action.
  • Avatar — Presence of a person, which Avatar shows with its own status indicator.

Resources