# Badge

> Badge highlights information such as notifications or counts in a non-intrusive way. Often paired with other elements like icons or navigation links.

Source: https://vaneui.com/docs/basic-components/badge

Import: `import { Badge, Card, Col, Row, Text, ThemeProvider, Title } from "@vaneui/ui"`

Badge adds a short label, such as an unread count, "Live" or "Pro", next to a title or inside a [NavLink](/docs/basic-components/navlink). It renders a `<span>` whose text stays on one line, and switches to `<a>` when `href` is set. For a tag or filter token, use a [Chip](/docs/basic-components/chip), and when clicking the label should run an action, use a [Button](/docs/basic-components/button).

## Basic usage

Badge highlights a short piece of information such as a count or status, and each `appearance` prop maps to a semantic color from the active theme. Badge defaults to `sm`, `secondary`, `outline`, `pill`, and `fontSemibold` in normal case. Add `uppercase` for a status-chip look.

```tsx demo
<Row flexWrap>
  <Badge primary>primary</Badge>
  <Badge accent>accent</Badge>
  <Badge secondary>secondary</Badge>
  <Badge tertiary>tertiary</Badge>
  <Badge success>success</Badge>
  <Badge danger>danger</Badge>
  <Badge warning>warning</Badge>
  <Badge info>info</Badge>
  <Badge inheritAppearance>inheritAppearance</Badge>
</Row>
```

## Sizes

Badges come in five sizes: `xs`, `sm` (default), `md`, `lg`, `xl`. The default has 12px text and is 20px tall. At every size the text is centered by the height of its capital letters. It sits in a `<span class="vane-text-run">`, which [How Button centers its label](/docs/basic-components/button#how-button-centers-its-label) explains.

```tsx demo
<Row flexWrap>
  <Badge xs>xs</Badge>
  <Badge>sm</Badge>
  <Badge md>md</Badge>
  <Badge lg>lg</Badge>
  <Badge xl>xl</Badge>
</Row>
```

## Variants

Badges can be styled as `filled`, `outline` (default), or `ghost`.

```tsx demo
<Col>
  <Row flexWrap>
    <Badge filled primary>primary</Badge>
    <Badge filled accent>accent</Badge>
    <Badge filled secondary>secondary</Badge>
  </Row>
  <Row flexWrap>
    <Badge outline primary>primary</Badge>
    <Badge outline accent>accent</Badge>
    <Badge outline secondary>secondary</Badge>
  </Row>
  <Row flexWrap>
    <Badge ghost primary>primary</Badge>
    <Badge ghost accent>accent</Badge>
    <Badge ghost secondary>secondary</Badge>
  </Row>
</Col>
```

## Shapes

Badges support different border radius styles: `rounded`, `pill` (default), and `sharp`.

```tsx demo
<Row flexWrap>
  <Badge pill>Pro</Badge>
  <Badge sharp>Pro</Badge>
  <Badge rounded>Pro</Badge>
</Row>
```

## Font weights

Badges support different font weights.

```tsx demo
<Row flexWrap>
  <Badge fontNormal>Premium</Badge>
  <Badge fontMedium>Premium</Badge>
  <Badge fontSemibold>Premium</Badge>
  <Badge fontBold>Premium</Badge>
</Row>
```

## Status dot

`dot` draws a small dot before the text, in the text color, for a status such as online, away or failing. With no text, the badge itself becomes the dot: an outline or ghost dot takes the text color and a filled one keeps its fill. Give a dot without text an `aria-label`, and it gets `role="img"`, so a screen reader reads the status. `dot` needs `@vaneui/ui` 1.8.0 or later.

```tsx demo
<Row flexWrap>
  <Badge success dot>Online</Badge>
  <Badge warning dot>Away</Badge>
  <Badge danger filled dot>Failing</Badge>
  <Badge success dot aria-label="Online"/>
  <Badge danger filled dot aria-label="Failing"/>
</Row>
```

## As Link

Pass `href` to render the badge as an `<a>`, useful for clickable status labels. When `href` is set, the badge gains a keyboard focus-visible outline by default (opt out with `noFocusVisible`).

```tsx demo
<Row flexWrap>
  <Badge href="#">Status</Badge>
  <Badge href="#" success filled>Live</Badge>
  <Badge href="#" warning>Pending</Badge>
</Row>
```

## Status badges in context

Badges work well as status indicators inside cards and other layout components.

```tsx demo
<Card>
  <Row justifyBetween>
    <Title>Production deploy</Title>
    <Badge success filled>Live</Badge>
  </Row>
  <Text>Build #1284 promoted to production 2 minutes ago.</Text>
</Card>
```

## Customizing

Set app-wide Badge defaults with `ThemeProvider`'s `themeDefaults`:

```tsx demo
<ThemeProvider themeDefaults={{
  badge: { success: true, uppercase: true },
}}>
  <Badge>Live</Badge>
</ThemeProvider>
```

## Frequently asked questions

### Why is my Badge gray?

Badge defaults to the `secondary` appearance, a neutral gray, so a bare Badge reads as a plain label. Name the status with an appearance prop such as `success`, `warning` or `danger`, and add `filled` for a solid fill: `<Badge success filled>Live</Badge>`. To change the default across an app, set it once on `ThemeProvider`, as [Customizing](#customizing) shows.

### Can I make a Badge clickable?

Give it an `href`, and it renders an `<a>` with a keyboard focus outline. A Badge with only `onClick` stays a plain `<span>`: it gets no role, no tab stop and no keyboard activation, so keyboard users cannot reach it. For a token that runs an action, use a [Chip](/docs/basic-components/chip#clickable-chips), which takes button semantics from `onClick`, or a [Button](/docs/basic-components/button).

### Why doesn't a Badge take the color of the Card it sits in?

Badge paints its own colors. It emits its appearance and variant, so a default Badge stays secondary outline inside a filled or colored Card. Set an appearance on the Badge itself, or pass `inheritAppearance` to take the colors of its parent. [Variant inheritance](/docs/customization/variant-inheritance#which-components-set-vs-inherit) lists which components paint their own colors and which inherit them.

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance | yes | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance |  | Info color appearance (cyan) |
| `inheritAppearance` | Appearance |  | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `disabled` | Disabled |  | Disable the component — reduces opacity, changes cursor to not-allowed, and prevents interaction |
| `dot` | Dot |  | Status dot before the text, in the text color; with no children only the dot shows |
| `flex1` | Flex |  | Take up remaining space (= `flex-1`, i.e. `flex: 1 1 0%`) |
| `flexAuto` | Flex |  | Grow but respect intrinsic size (= `flex-auto`, i.e. `flex: 1 1 auto`) |
| `flexNone` | Flex |  | Don't grow and don't shrink (= `flex-none`, i.e. `flex: none`) |
| `fontSans` | Font Family | yes | Sans-serif font family (default) — emits font-sans |
| `fontSerif` | Font Family |  | Serif font family — emits font-serif |
| `fontMono` | Font Family |  | Monospace font family — emits font-mono |
| `fontHeading` | Font Family |  | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading |
| `italic` | Font Style |  | Italic font style |
| `notItalic` | Font Style |  | Not italic (normal) font style |
| `fontThin` | Font Weight |  | Thin font weight (100) — emits font-thin |
| `fontExtralight` | Font Weight |  | Extra light font weight (200) — emits font-extralight |
| `fontLight` | Font Weight |  | Light font weight (300) — emits font-light |
| `fontNormal` | Font Weight |  | Normal font weight (400) — emits font-normal |
| `fontMedium` | Font Weight |  | Medium font weight (500) — emits font-medium |
| `fontSemibold` | Font Weight | yes | Semibold font weight (600) — emits font-semibold |
| `fontBold` | Font Weight |  | Bold font weight (700) — emits font-bold |
| `fontExtrabold` | Font Weight |  | Extra bold font weight (800) — emits font-extrabold |
| `fontBlack` | Font Weight |  | Black font weight (900) — emits font-black |
| `inheritSize` | Inherit Size |  | Inherit font-size and line-height from the nearest parent typography element |
| `noInheritSize` | Inherit Size |  | Keep own font-size; do not inherit from parent |
| `padding` | Padding | yes | Enable internal padding |
| `paddingX` | Padding |  | Enable only horizontal padding |
| `paddingY` | Padding |  | Enable only vertical padding |
| `noPadding` | Padding |  | Disable internal padding |
| `pill` | Shape | yes | Fully rounded corners (circular) |
| `sharp` | Shape |  | No rounded corners (square) |
| `rounded` | Shape |  | Medium rounded corners (default) |
| `noShrink` | Shrink |  | Prevent the flex item from shrinking below its content size (= `shrink-0`) |
| `xs` | Size |  | Extra small size |
| `sm` | Size | yes | Small size |
| `md` | Size |  | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `skeleton` | Skeleton |  | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too |
| `textLeft` | Text Align |  | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `underline` | Text Decoration |  | Add underline decoration below text |
| `lineThrough` | Text Decoration |  | Add strikethrough/line-through decoration across text |
| `noUnderline` | Text Decoration |  | Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none) |
| `overline` | Text Decoration |  | Add overline decoration above text |
| `uppercase` | Text Transform |  | Transform text to uppercase |
| `lowercase` | Text Transform |  | Transform text to lowercase |
| `capitalize` | Text Transform |  | Capitalize first letter of each word |
| `normalCase` | Text Transform |  | Normal text case (no transformation) |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant | yes | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |
| `breakNormal` | Word Break |  | Reset breaking - overflow-wrap and word-break normal |
| `breakWords` | Word Break |  | Break long words to prevent overflow - overflow-wrap: break-word |
| `breakAll` | Word Break |  | Break between any two characters - word-break: break-all |
| `breakKeep` | Word Break |  | Do not break CJK text - word-break: keep-all |

Layout and utility props (Border, Cursor, Display, Flex Direction, Focus Visible, Gap, Height, Hide, Items, Justify, Overflow, Position, Responsive Sizing, Responsive Width, Ring, Shadow, Show, Transition, Transparent, Whitespace, Width, Wrap) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
