Skip to content

Badge

A short label for a status, count or category. Seven colours, filled or outlined, three sizes.

Version 0.2.0 ·

Colours
Direction
Theme
Viewport

Installation

bunx --bun shadcn@latest add @dga/badge

Usage

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

<Badge variant="success">مقبول</Badge>

A badge is a short, non-interactive label. For labels the user can remove or select, use a Tag.

Anatomy

  • Root: a <span>.
  • Icon (optional): before the text.
  • Label: the text.

Examples

Sizes, shape and icons

sm is 20px, md 24px (default) and lg 32px high. rounded makes a pill, which suits counts. iconOnly makes a square (or circle) badge and needs an aria-label.

Sizes

RTL

Padding and icon position follow the reading direction.

LTR (English)
RTL (Arabic)

Accessibility

  • A <span> with no role. The text is read in place, so put the meaning in the text, not only in the colour (WCAG 1.4.1).
  • For a count, add context: <Badge>3<span className="sr-only"> unread</span></Badge>.
  • Icon-only badges need an aria-label, or aria-hidden if they are decorative.

API Reference

Badge

A short, non-interactive label for status, counts or categories.

Badge props
PropTypeDefault
"on-color" | "neutral" | "success" | "error" | "warning" | "info" | "purple" | "orange"

Colour family. `on-color` is for badges on brand fills.

"neutral"
"sm" | "md" | "lg"

Height: `sm` 20px, `md` 24px, `lg` 32px.

"md"
boolean

Outlined instead of filled.

false
boolean

Fully rounded (pill) corners.

false
boolean

Square, icon only. Needs an `aria-label`.

false

Also accepts the props of the element it renders.

Deviations from DGA

ChangeReason
--badge-neutral-background (new)Badge neutral fill: neutral-50 as on the site; neutral-800 in dark mode.
--badge-neutral-border (new)Badge neutral border: neutral-200 as on the site; neutral-700 in dark mode.
--badge-neutral-text (new)Badge neutral label and icon: neutral-700 as on the site; neutral-200 in dark mode.
--badge-neutral-border-outlined (new)Badge neutral outlined border: neutral-500 as on the site; neutral-400 in dark mode.

View all 33 deviations for this component

Contrast

92 pairs checked · all pass WCAG 2.1 AAShow 16 states
Variant / stateLightDark
neutral / filled9.73:1 AAA9.64:1 AAA
neutral / outlined9.73:1 AAA12.04:1 AAA
success / filled6.30:1 AA7.57:1 AAA
success / outlined6.31:1 AA10.38:1 AAA
error / filled6.04:1 AA7.04:1 AAA
error / outlined6.29:1 AA9.01:1 AAA
warning / filled5.20:1 AA8.57:1 AAA
warning / outlined5.19:1 AA11.30:1 AAA
info / filled5.57:1 AA7.49:1 AAA
info / outlined5.72:1 AA9.88:1 AAA
purple / filled9.73:1 AAA6.82:1 AA
purple / outlined10.04:1 AAA8.78:1 AAA
orange / filled5.39:1 AA7.50:1 AAA
orange / outlined5.52:1 AA9.66:1 AAA
on-color / filled6.30:1 AA6.30:1 AA
on-color / outlined4.74:1 AA4.74:1 AA

Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report