Theme

Customize appearance

Components

Badge

Label an item with a compact status or category.

View component source ↗

Preview

A minimal example to get started.

NewDraftArchivedFailed

Installation

Install this component and its dependencies in a project initialized with shadcn.

pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/badge.json

Usage

This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.

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

export default function Example() {
  return (
    <div className="flex flex-wrap gap-2">
      <Badge>New</Badge>
      <Badge variant="secondary">Draft</Badge>
      <Badge variant="outline">Archived</Badge>
      <Badge variant="destructive">Failed</Badge>
    </div>
  );
}

API reference

Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.

Badge
Badge properties
PropTypeDefaultDescription
ref
React.Ref<HTMLSpanElement> | undefined
React.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).
defaultChecked
boolean | undefined
boolean | undefined
—Initial checked state for an uncontrolled control.
defaultValue
string | number | readonly string[] | undefined
string | number | readonly string[] | undefined
—Initial value for an uncontrolled component.
className
string | undefined
string | undefined
—Additional CSS classes merged with the component styles.
id
string | undefined
string | undefined
—Unique identifier used to associate labels and descriptions.
children
React.ReactNode
React.ReactNode
—Content rendered inside this component.
onFocus
React.FocusEventHandler<HTMLSpanElement> | undefined
React.FocusEventHandler<HTMLSpanElement> | undefined
—Called when the control receives focus.
onBlur
React.FocusEventHandler<HTMLSpanElement> | undefined
React.FocusEventHandler<HTMLSpanElement> | undefined
—Called when the control loses focus.
onChange
React.ChangeEventHandler<HTMLSpanElement, Element> | undefined
React.ChangeEventHandler<HTMLSpanElement, Element> | undefined
—Called when the underlying form control changes; inspect the event for its value.
onKeyDown
React.KeyboardEventHandler<HTMLSpanElement> | undefined
React.KeyboardEventHandler<HTMLSpanElement> | undefined
—Called when a key is pressed while this element is focused.
onClick
React.MouseEventHandler<HTMLSpanElement> | undefined
React.MouseEventHandler<HTMLSpanElement> | undefined
—Called when the element is activated.
render
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…
React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}> | undefined
—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
variant
"link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined
"link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined
"default"Visual treatment of the component.

Usage notes

Choose a variant that matches the meaning. Keep labels short and do not rely on color alone.