🌴Ocean UI
Base components

Badge

A versatile badge component for displaying labels, status indicators, counts, or metadata. Built with Tailwind CSS and styled using Ocean UI design tokens for consistent theming.

Example

BadgeSecondaryDestructiveOutline
Verified89920+

How to install and use

1

Complete the manual installation setup

If you haven't already completed the first 4 steps of the manual installation guide, please do so before continuing to install these components.

2

Create a badge.tsx file and paste the following code into it.

/components/ui/badge.tsx

import { cva, type VariantProps } from "class-variance-authority";
import type { ComponentProps } from "react";

import { cn } from "@/lib/utils";

const badgeVariants = cva(
  "inline-flex items-center justify-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 [&>svg]:pointer-events-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 transition-[color,box-shadow] overflow-hidden",
  {
    variants: {
      variant: {
        default:
          "border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",
        secondary:
          "border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",
        destructive:
          "border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40",
        outline:
          "border-border bg-transparent text-foreground [a&]:hover:bg-muted [a&]:hover:text-foreground",
      },
    },
    defaultVariants: {
      variant: "default",
    },
  }
);

export interface BadgeProps
  extends ComponentProps<"span">,
    VariantProps<typeof badgeVariants> {}

function Badge({ className, variant, ...props }: BadgeProps) {
  return (
    <span
      data-slot="badge"
      className={cn(badgeVariants({ variant }), className)}
      {...props}
    />
  );
}

export { Badge, badgeVariants };
3

Finally, Choose any example you like and add it to your project.
For instance, create a new file at components/shared/{example-component-name}.tsx, paste the example code into that file, and then import and use the component wherever you need it in your application.

The Badge component is a simple, semantic component built with Tailwind CSS using Ocean UI design tokens. It uses a pill-shaped design by default and supports multiple visual variants.

Overview

The Badge component is a small UI element used to display labels, status indicators, counts, or metadata. It features a pill-shaped design with consistent padding and typography, making it ideal for tags, status badges, notification counts, and more.

Variants

The Badge component supports four visual variants:

  • default: Primary badge with brand color background
  • secondary: Secondary badge with subtle background
  • outline: Outlined badge with transparent background and border
  • destructive: Badge for destructive or error states

Features

  • Pill Shape: Rounded-full design by default for a modern look
  • Icons: Support for leading and trailing icons via children
  • Flexible Content: Can display text, numbers, icons, or images
  • Accessibility: Semantic HTML with proper focus states
  • Customizable: All styles can be overridden via className prop
  • Design Tokens: Uses Ocean UI design tokens for consistent theming

Select Examples

Basic Badge

The basic badge demo shows all available variants along with examples of badges with icons and numeric counts.

BadgeSecondaryDestructiveOutline
Verified89920+

Variants

All four badge variants: default, secondary, destructive, and outline. Each variant uses Ocean UI design tokens for consistent theming.

DefaultSecondaryDestructiveOutline

Status

Status badges with icons to indicate different states like Todo, In Progress, Done, and Cancelled. Uses design tokens for colors instead of hardcoded values.

Todo In Progress Done Cancelled

With Image

Badges can include images, such as avatars or profile pictures. Images are displayed as rounded circles and can be positioned before or after the label text.

shadcnshadcnshadcnshadcn

Indicator on Buttons

Badges can be used as notification indicators on buttons. Position them absolutely to show counts, dots, or icons. Empty badges automatically shrink to a small dot.

On this page