> Leaf UI 0.17.3 · Package: @ifhover/leaf-ui · Source: c3221834f84f2f48481a2054026b713456f8e5dc
> Browser documentation: https://ifhover.github.io/leaf-ui/en/components/badge.html

> For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt.

# Badge

Show counts or unread notifications.


## Basic usage

Set a count with `count` and pass `children` to attach the badge to content.


8

basic.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/badge/basic.tsx"
import { Badge, Button } from '@ifhover/leaf-ui';
import { Bell } from 'lucide-react';

export function BadgeBasic() {
  return (
    <Badge count={8} aria-label="8 unread notifications">
      <Button variant="outline" startIcon={<Bell />} aria-label="Notifications" />
    </Badge>
  );
}
```

Expand code


## Examples

### Count rules

Counts above `max` show the limit with a plus sign. Zero is hidden unless `showZero` is set.


Over limit

99+

Show zero

0

counts.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/badge/counts.tsx"
import { Badge, Button, Flex, Grid, Text } from '@ifhover/leaf-ui';
import { Bell } from 'lucide-react';

export function BadgeCounts() {
  return (
    <Grid columns={{ xs: 1, sm: 2 }} gap={16} align="center">
      <Text tone="muted">Over limit</Text>
      <Flex align="center" wrap>
        <Badge count={120} aria-label="120 unread notifications">
          <Button startIcon={<Bell />} aria-label="Notifications" />
        </Badge>
      </Flex>
      <Text tone="muted">Show zero</Text>
      <Flex align="center" wrap>
        <Badge count={0} showZero aria-label="0 unread notifications">
          <Button startIcon={<Bell />} aria-label="Notifications" />
        </Badge>
      </Flex>
    </Grid>
  );
}
```

Expand code

### Dot reminders

Set `dot` to indicate new content without a count. Use `aria-label` to describe the notification.


dot.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/badge/dot.tsx"
import { Badge, Button } from '@ifhover/leaf-ui';
import { Mail } from 'lucide-react';

export function BadgeDot() {
  return (
    <Badge dot aria-label="Unread messages">
      <Button variant="outline" startIcon={<Mail />} aria-label="Messages" />
    </Badge>
  );
}
```

Expand code

### Inside placement

Set `placement="inside"` to place the indicator inside the content. Leave room so it does not cover text or icons.


inside.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/badge/inside.tsx"
import { Badge, Button } from '@ifhover/leaf-ui';
import { Bell } from 'lucide-react';

export function BadgeInside() {
  return (
    <Badge dot placement="inside" aria-label="Unread notifications">
      <Button variant="outline" startIcon={<Bell />} aria-label="Notifications" />
    </Badge>
  );
}
```

Expand code


## API

### Badge API

Configuration for badge counts, dot indicators and attachment placement.

| Property    | Type                    | Default     | Description                                                                                      |
| ----------- | ----------------------- | ----------- | ------------------------------------------------------------------------------------------------ |
| `children`  | `ReactNode`             | Required    | Content the indicator attaches to; no badge renders without content                              |
| `count`     | `number \| string`      | —           | Badge content                                                                                    |
| `max`       | `number`                | `99`        | Display max+ above this count                                                                    |
| `showZero`  | `boolean`               | `false`     | Show a zero count                                                                                |
| `dot`       | `boolean`               | `false`     | Use a notification dot                                                                           |
| `placement` | `'outside' \| 'inside'` | `'outside'` | Attached indicator position: outside by default, or inside the top-right corner; mirrored in RTL |
| `color`     | `string`                | —           | Custom indicator color                                                                           |
