Components

Badge

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

PreviewSource
BadgeSecondaryDestructiveOutline

Installation

Complete the project setup first. The init command configures TypeScript, Vite, Tailwind CSS v4, and Preact compatibility.

CLI

Run init once using the installation guide, then add this component. The CLI copies the required source files and installs their exact dependencies with Bun.

bunx --bun github:LiasCode/shadcn-preact#main add badge

Add --dry-run to review the changes. Existing modified files are protected; use --overwrite only when you want to replace them.

Manual installation / degit (optional)

1. Install dependencies

bun add --exact class-variance-authority@0.7.1 cn@0.4.0 preact@11.0.1 tw-animate-css@1.4.0

2. Copy the component with degit

Run this from your project root. It selects badge.tsx, its local dependencies, and both licenses directly from the repository, then copies them into src/components/ui.

bunx degit@3.10.0 https://github.com/LiasCode/shadcn-preact#main ./.cache/shadcn-preact/badge --files LICENSE.md,registry/ui/badge.tsx,registry/ui/lib/utils.ts,registry/ui/primitives/LICENSE,registry/ui/primitives/internals/empty.ts,registry/ui/primitives/internals/getReactElementRef.ts,registry/ui/primitives/internals/getStateAttributesProps.ts,registry/ui/primitives/internals/mergeObjects.ts,registry/ui/primitives/internals/resolveClassName.ts,registry/ui/primitives/internals/resolveStyle.ts,registry/ui/primitives/internals/types.ts,registry/ui/primitives/internals/useMergedRefs.ts,registry/ui/primitives/internals/useRefWithInit.ts,registry/ui/primitives/internals/useRenderElement.ts,registry/ui/primitives/merge-props/index.ts,registry/ui/primitives/use-render/index.ts --force
mkdir -p ./src/components/ui
cp -R ./.cache/shadcn-preact/badge/registry/ui/. ./src/components/ui/
cp ./.cache/shadcn-preact/badge/LICENSE.md ./src/components/ui/LICENSE.md

The temporary copy lives in .cache/shadcn-preact/badge. Existing components stay in place; shared source files are updated from main.

Selected source files (15)

Usage

import { Badge } from "./components/ui/badge"
<Badge variant="default | outline | secondary | destructive">Badge</Badge>

Examples

Variants

Use the variant prop to change the variant of the badge.

VariantsSource
DefaultSecondaryDestructiveOutlineGhost

With Icon

You can render an icon inside the badge. Use data-icon="inline-start" to render the icon on the left and data-icon="inline-end" to render the icon on the right.

With IconSource
VerifiedBookmark
Example requirements
bun add --exact lucide-preact@1.55.0

With Spinner

You can render a spinner inside the badge. Remember to add the data-icon="inline-start" or data-icon="inline-end" prop to the spinner.

With SpinnerSource
DeletingGenerating
Example requirements

Also uses: Spinner.

Custom Colors

You can customize the colors of a badge by adding custom classes such as bg-green-50 dark:bg-green-800 to the Badge component.

Custom ColorsSource
BlueGreenSkyPurpleRed

Reference

See the official Badge documentation for composition patterns and API details. This page uses the Preact port and examples from the pinned upstream revision.

Component source