Badge
A versatile badge component for displaying status, labels, or metadata with multiple visual variants.
Installation
Install the component directly into your project using the Pittaya CLI.
npx pittaya@latest add badge
When to use
Use badges to highlight important information, display statuses, categorize content, or draw attention to specific metadata. They are perfect for labels, counts, notifications, and status indicators.
Badges work well in tables, cards, lists, and navigation elements where you need to convey supplementary information without taking up too much space.
Best practices
- Keep badge text concise—use 1-3 words maximum for better readability.
- Use consistent color coding across your application (e.g., green for success, red for errors).
- Choose the
stablevariant for approved or production-ready states,betafor experimental features, anddeprecatedfor outdated content. - Combine badges with icons to enhance recognition and provide visual context.
- Avoid overusing badges—too many can create visual clutter and reduce their effectiveness.
Accessibility
The Badge component uses semantic HTML with proper focus states and color contrast ratios. When using badges to convey status information, ensure the meaning is not communicated solely through color.
If using badges as interactive elements (links), the asChild prop allows you to render them as anchor tags while maintaining proper keyboard navigation and screen reader support.
Examples
Combine variants and sizes to meet your needs.
All variants
Demonstration of all available badge variants for different use cases.
With icons
Combine badges with icons to provide additional visual context and improve recognition.
Interactive badge
Use the asChild prop to render badges as clickable links while maintaining their visual style.
Properties
TSX interface that combines variants and default attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'default' | 'secondary' | 'destructive' | 'outline' | 'stable' | 'beta' | 'deprecated' | 'default' | Defines the visual style of the badge. Choose variants based on the type of information being conveyed. |
asChild | boolean | false | When enabled, uses Radix's Slot to merge styles with the child element, allowing you to render badges as links or other interactive elements. |