Skip to Content

Built by moveinready.casa  and the community

Shadcn Docs

Badge

Displays a badge or a component that looks like a badge.

Usage

import {Badge} from "@/components/ui/badge"; <Badge>Badge</Badge>;

Badge

PropTypeDefaultDescription
variant"default" | "secondary" | "destructive" | "outline""default"The visual variant of the badge.
size"sm" | "md" | "lg" | "xl""md"Sets the size of the badge. Controls padding, text size, and icon size.
borderRadius"none" | "sm" | "md" | "lg" | "xl""lg"Sets the border radius of the badge.
disabledbooleanfalseWhether the badge is disabled.
status"idle" | "loading" | "error""idle"Sets the status indicator state.
loadingbooleanfalseConvenience prop to show loading state. Overrides status.
indicator(state: BadgeStatus) => React.ReactNodeundefinedCustom indicator renderer function.
baseClassNamestringundefinedCustom Tailwind classes to apply to the badge.
asChildbooleanfalseIf true, clones props to the nearest child instead of rendering a View.
childrenReact.ReactNode-The content to display inside the badge.

Accessibility

The Badge component includes:

  • Proper accessibilityState for disabled badges
  • Semantic structure for screen readers
  • Focus management when used as interactive elements

Styling

The Badge component uses Tailwind variants for consistent styling. You can customize the appearance using:

  • variant prop for color schemes
  • size prop for sizing (padding, text size, and icon size)
  • borderRadius prop for corner styling
  • baseClassName prop for custom Tailwind classes
  • disabled prop for opacity changes

Size Variants

The size prop controls multiple styling aspects:

  • sm: Compact badge with px-1.5 py-0.5, text-xs, and 12px icons
  • md: Default badge with px-2 py-0.5, text-xs, and 12px icons
  • lg: Large badge with px-2.5 py-1, text-sm, and 16px icons
  • xl: Extra large badge with px-3 py-1.5, text-base, and 20px icons

Status Indicators

The Badge supports status indicators for loading and error states:

  • Loading: Shows a spinning indicator by default
  • Error: Shows an error indicator by default
  • Idle: No indicator shown
  • Custom: Use the indicator prop for custom indicators

The loading boolean prop provides a convenient way to show loading state without managing the status prop directly.

shadcn-native

Built by moveinready.casa and the community