Badge
A flexible badge component for tagging, categorization, and status indication, supporting multiple variants and customizations.
Customize Your Badge
Leave blank to use variant color
Leave blank for variant's text
Leave blank for variant's hover
Leave blank for variant's hover text
Only applies if size > 0
Introduction
The Badge component provides a simple way to highlight and categorize content within your application. Use it for displaying statuses, counts, tags, or any other concise metadata.
Badges are designed to be lightweight and unobtrusive, making them perfect for supplementary information.
Installation
Install the badge component using:
File Structure
Here’s the file structure for the Badge component:
Variants
Default
Secondary
Destructive
Outline
Examples
Status Indicators
Different Sizes
With Counters
Custom Colors
Tags & Categories
Props
The Badge
component comes with the following customizable props:
Prop | Type | Default |
---|---|---|
variant | "default" | "secondary" | "destructive" | "outline" | "default" |
className | string | - |
children | React.ReactNode | - |
Customization
The Badge component can be customized further by:
Use Cases
The Badge component is perfect for:
- Status Indicators: Highlight statuses like “Active,” “Inactive,” or “Pending.”
- Tags & Categories: Label content, filters, or metadata for easy identification.
- Counters: Display notification counts or other numerical values.
- Labels: Add contextual information to UI elements.
- Feature Flags: Indicate new, beta, or deprecated features.
Accessibility
The Badge component follows these accessibility best practices:
- Color Contrast: All variants maintain proper color contrast ratios for readability.
- Screen Reader Support: Uses meaningful content that provides context to assistive technologies.
- Keyboard Navigation: Fully navigable when used with interactive elements.
- Focus Indicators: Includes visible focus rings when the badge is interactive.
When using badges to convey important information, ensure the meaning is not conveyed by color alone. Use text or additional indicators for users with color vision deficiencies.
Features
The Badge
component provides the following features:
- Multiple Variants: Choose from default, secondary, destructive, and outline styles to match your design needs.
- Flexible Styling: Easily customize with additional classes or inline styles.
- Status Indicators: Combine with colored dots for status representation.
- Counters: Display numerical values alongside labels.
- Responsive: Works well at any screen size.
- Accessibility: Built with screen readers and keyboard navigation in mind.
Conclusion
The Badge component is a versatile, accessible, and lightweight solution for adding visual indicators to your application. Its flexibility through variants and customization options makes it adaptable to a wide range of use cases while maintaining a consistent design language across your Next.js application.