Veil UI
Components

Badge

A compact label for status, counts and categories.

Installation

$ npx veil-ui@latest add badge

Usage

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

<Badge variant="outline">Draft</Badge>;

Examples

Basic

New

Variants

DefaultSecondaryOutlineMutedDestructive

With icon

Operationalv0.1.0

API reference

PropTypeDefaultDescription
variant"default" | "secondary" | "outline" | "muted" | "destructive""default"Visual style of the badge.
asChildbooleanfalseRender the child element instead of a span.
...propsReact.ComponentProps<"span">—All native span attributes.

Accessibility

  • Badges are plain text containers; avoid using them as the only way to convey status. Pair color with a label or icon.
  • When a badge is interactive, use asChild with a real link or button.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add badge --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Primitive } from "reka-ui";
import { computed } from "vue";

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

import { badgeVariants, type BadgeVariants } from "./variants";

defineOptions({ inheritAttrs: false });

const props = withDefaults(
  defineProps<{
    variant?: BadgeVariants["variant"];
    asChild?: boolean;
    class?: string;
  }>(),
  { asChild: false },
);

const classes = computed(() =>
  cn(badgeVariants({ variant: props.variant }), props.class),
);
</script>

<template>
  <Primitive
    :as="asChild ? undefined : 'span'"
    :as-child="asChild"
    data-slot="badge"
    :data-variant="variant ?? 'default'"
    :class="classes"
    v-bind="$attrs"
  >
    <slot />
  </Primitive>
</template>

On this page