Badge
React Badge components are used to display small labels, counts, status indicators, or metadata with semantic colors and optional icons. They are commonly used for notifications, categories, tags, and metadata across interfaces.
This Badge component is built with React and styled using Tailwind CSS, giving developers control over size, color, and icon placement.
Installation
Install the component using the Tailgrids CLI.
npx @tailgrids/cli@latest add badgeUsage
Import the component and pass the required props.
import { Badge } from "@/components/tailgrids/badge";
export const BadgeExample = () => <Badge variant="default">New</Badge>;Examples
Sizes
Badge component supports three predefined sizes: sm, md, and lg.
Variants
The variant prop selects the badge style: default, secondary, destructive, success, warning, outline, ghost and link. For other colors, pass Tailwind palette classes through className.
With Icons
Add icons before or after your text using the leadingIcon and trailingIcon props.
Custom
Use custom styles or positioning to create unique badges for specific use cases.
API Reference
Badge
Extends span element props.
| Prop | Type | Default | Description |
|---|---|---|---|
size | 'sm' | 'md' | 'lg' | 'sm' | Sets the badge size |
variant | 'default' | 'secondary' | 'destructive' | 'success' | 'warning' | 'outline' | 'ghost' | 'link' | 'default' | Sets the badge style |
leadingIcon | React.ReactNode | - | Icon before the text |
trailingIcon | React.ReactNode | - | Icon after the text |
className | string | - | Additional CSS classes |
children | React.ReactNode | - | Badge content |
Notes
- Icons are automatically sized to
12px(0.75rem) via the[&>svg]:size-3class - Padding adjusts automatically based on the presence of prefix/suffix icons
- All standard
spanHTML attributes are supported
