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, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/badge.md.

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
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>
  );
}

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
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>
  );
}

Dot reminders

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

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>
  );
}

Inside placement

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

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>
  );
}

API

Badge API

Configuration for badge counts, dot indicators and attachment placement.

PropertyTypeDefaultDescription
childrenReactNodeRequiredContent the indicator attaches to; no badge renders without content
countnumber | string—Badge content
maxnumber99Display max+ above this count
showZerobooleanfalseShow a zero count
dotbooleanfalseUse a notification dot
placement'outside' | 'inside''outside'Attached indicator position: outside by default, or inside the top-right corner; mirrored in RTL
colorstring—Custom indicator color