Notification badge
Shows a red counter or dot on the corner of an icon or a link to signal unread or new items.
5
size
<NotificationBadge size="content" />When to use
- To show how many unread items wait behind an icon, a sidebar link or a list row: tickets, notifications, messages.
- To show that something is new when the number does not matter (
size="dot").
When not to use
- A label that describes an item. Use Badge or Tag.
- A processing status. Use Status badge.
- A message the user must read. Use Alert.
Sizes
The size prop picks between a counter and a dot. The parent must be position: relative: the badge is absolute on its top-right corner.
3
42
+99
- Numbers above 99 show as
+99. - A falsy
children(0, empty orundefined) renders nothing, so you can pass the count directly.
Examples
Inside a row, reset the position with className so the counter flows with the content.
Chamados abertos
7
Content
- Pass a number. Do not pass text.
- Show the count only when it is greater than zero.
- Use the dot when the exact count is not useful.
Accessibility
- It renders a
divwith no role and no accessible name. A screen reader reads the digits without context. - Put the meaning on the parent control:
aria-label="3 notificações não lidas". In the stories the Button names the count. - The dot has no text at all. Always describe it in the parent’s accessible name (“Notificações, há itens novos”).
- Red is not the only signal when the counter shows a number. The dot depends on color and position: do not use it alone to carry critical information.
- It is not interactive and has no focus state. The parent handles click and keyboard.
Code
import { NotificationBadge } from "@repo/ui/notification-badge";
<div className="relative">
<Button
aria-label="3 notificações não lidas"
size="smIcon"
variant="secondary"
>
<Bell aria-hidden="true" className="size-4" />
</Button>
<NotificationBadge>{3}</NotificationBadge>
</div>;
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children | unknown | — | Count to show. Numbers above 99 display as `+99`. An empty or zero value renders nothing |
size | "content" | "dot" | content | `content` shows the count. `dot` shows a small dot without a number |
Known issues
| Issue | Effect |
|---|---|
The background is bg-red-400 and the text is text-white. |
Hardcoded palette colors instead of semantic tokens: they do not follow Light, Dark and Darker themes. |
| It has no role or accessible name. | Screen readers announce a bare number, or nothing for the dot, unless the parent is labeled. |
The dot only renders when children is truthy, but never shows them. |
The dot needs a throwaway child such as 1. Passing none hides it. |
"+99" formatting applies only when children is a number. |
A numeric string such as "150" is shown in full and can overflow the 16px circle. |
The dot is h-1.5 w-1.5 (6px). |
Very small and easy to miss on older monitors. |
NotificationBadgeProps is an interface. |
Code only: the repository prefers type. |