Badge
A small pill used to label status, counts or categories.
A small pill for a count, a state or a label. The dot variant puts a filled circle before the text, which is how a status reads at a glance without relying on the pill’s colour alone.
newt-badgeimport { Badge } from "@/registry/bases/newt/ui/badge"
export default function BadgeDemo() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge variant="brand" dot>
Brand
</Badge>
<Badge variant="success" dot>
Online
</Badge>
<Badge variant="danger" dot>
Error
</Badge>
</div>
)
}<script setup lang="ts">
import { Badge } from "~~/registry/bases/newt/ui/badge"
</script>
<template>
<div class="flex flex-wrap items-center gap-2">
<Badge variant="brand" dot>Brand</Badge>
<Badge variant="success" dot>Online</Badge>
<Badge variant="danger" dot>Error</Badge>
</div>
</template>Installation
npx newtui@latest add badgenpx shadcn@latest add @newtui/badgenpx shadcn-vue@latest add @newtui/badgepnpm dlx newtui@latest add badgepnpm dlx shadcn@latest add @newtui/badgepnpm dlx shadcn-vue@latest add @newtui/badgeyarn dlx newtui@latest add badgeyarn dlx shadcn@latest add @newtui/badgeyarn dlx shadcn-vue@latest add @newtui/badgebunx newtui@latest add badgebunx shadcn@latest add @newtui/badgebunx shadcn-vue@latest add @newtui/badgedeno run -A npm:newtui@latest add badgedeno run -A npm:shadcn@latest add @newtui/badgedeno run -A npm:shadcn-vue@latest add @newtui/badgevlx newtui@latest add badgevlx shadcn@latest add @newtui/badgevlx shadcn-vue@latest add @newtui/badgevp dlx newtui@latest add badgevp dlx shadcn@latest add @newtui/badgevp dlx shadcn-vue@latest add @newtui/badgenubx newtui@latest add badgenubx shadcn@latest add @newtui/badgenubx shadcn-vue@latest add @newtui/badgenlx newtui@latest add badgenlx shadcn@latest add @newtui/badgenlx shadcn-vue@latest add @newtui/badgeupx newtui@latest add badgeupx shadcn@latest add @newtui/badgeupx shadcn-vue@latest add @newtui/badge- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install class-variance-authoritypnpm add class-variance-authorityyarn add class-variance-authoritybun add class-variance-authoritydeno add npm:class-variance-authorityvlt install class-variance-authorityvp add class-variance-authoritynub add class-variance-authorityni class-variance-authorityupm add class-variance-authority- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"
import { cn } from "@/lib/utils"
const badgeVariants = cva(
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-semibold leading-4",
{
variants: {
variant: {
default: "bg-newt-bg-elevated text-newt-text-secondary",
brand: "bg-[rgba(88,101,242,0.15)] text-newt-mention-text",
success: "bg-[rgba(35,165,90,0.15)] text-[#45c178]",
warning: "bg-[rgba(240,178,50,0.15)] text-newt-mention-role",
danger: "bg-[rgba(242,63,66,0.15)] text-[#f4878a]",
},
dot: {
true: "before:h-1.5 before:w-1.5 before:rounded-full before:bg-current before:content-['']",
false: "",
},
},
defaultVariants: {
variant: "default",
dot: false,
},
}
)
export interface BadgeProps
extends
React.HTMLAttributes<HTMLSpanElement>,
VariantProps<typeof badgeVariants> {}
const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
({ className, variant, dot, ...props }, ref) => (
<span
ref={ref}
className={cn(badgeVariants({ variant, dot }), className)}
{...props}
/>
)
)
Badge.displayName = "Badge"
export { Badge, badgeVariants }<script setup lang="ts">
import type { HTMLAttributes } from "vue"
import { cn } from "@/lib/utils"
import { badgeVariants, type BadgeVariants } from "."
const props = defineProps<{
class?: HTMLAttributes["class"]
variant?: BadgeVariants["variant"]
dot?: boolean
}>()
</script>
<template>
<span
:class="
cn(badgeVariants({ variant: props.variant, dot: props.dot }), props.class)
"
>
<slot />
</span>
</template>import { cva, type VariantProps } from "class-variance-authority"
export { default as Badge } from "./Badge.vue"
export const badgeVariants = cva(
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-semibold leading-4",
{
variants: {
variant: {
default: "bg-newt-bg-elevated text-newt-text-secondary",
brand: "bg-[rgba(88,101,242,0.15)] text-newt-mention-text",
success: "bg-[rgba(35,165,90,0.15)] text-[#45c178]",
warning: "bg-[rgba(240,178,50,0.15)] text-newt-mention-role",
danger: "bg-[rgba(242,63,66,0.15)] text-[#f4878a]",
},
dot: {
true: "before:h-1.5 before:w-1.5 before:rounded-full before:bg-current before:content-['']",
false: "",
},
},
defaultVariants: {
variant: "default",
dot: false,
},
}
)
export type BadgeVariants = VariantProps<typeof badgeVariants>Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Badge to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Badge to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Badge } from "@/components/ui/badge"
export function Example() {
return <Badge />
}<script setup lang="ts">
import { Badge } from "@/components/ui/badge"
</script>
<template>
<Badge />
</template>Examples
Variants
The five variants without the dot. Pick one for what the badge reports, and let the word say it too, so the state survives without its colour.
newt-badgeimport { Badge } from "@/registry/bases/newt/ui/badge"
/* Each variant says what is being reported; the word carries it too. */
export default function BadgeVariantsDemo() {
return (
<div className="flex flex-wrap items-center gap-2">
<Badge>Member</Badge>
<Badge variant="brand">New</Badge>
<Badge variant="success">Verified</Badge>
<Badge variant="warning">Pending</Badge>
<Badge variant="danger">Banned</Badge>
</div>
)
}<script setup lang="ts">
import { Badge } from "~~/registry/bases/newt/ui/badge"
</script>
<template>
<!-- Each variant says what is being reported; the word carries it too. -->
<div class="flex flex-wrap items-center gap-2">
<Badge>Member</Badge>
<Badge variant="brand">New</Badge>
<Badge variant="success">Verified</Badge>
<Badge variant="warning">Pending</Badge>
<Badge variant="danger">Banned</Badge>
</div>
</template>Counts
A badge at the end of a row carries an unread count. The number alone says nothing to a screen reader, so each one holds a visually hidden word for what it counts.
newt-badgeimport { Badge } from "@/registry/bases/newt/ui/badge"
const CHANNELS = [
{ name: "announcements", count: 1, variant: "brand" },
{ name: "general", count: 12, variant: "danger" },
{ name: "off-topic", count: 3, variant: "default" },
] as const
/* A bare number means nothing to a screen reader, so each count says what it counts. */
export default function BadgeCountsDemo() {
return (
<div className="flex w-full max-w-xs flex-col gap-1">
{CHANNELS.map((channel) => (
<div
key={channel.name}
className="flex items-center justify-between gap-3 rounded-sm px-2 py-1.5 text-sm text-newt-text-secondary"
>
<span className="truncate"># {channel.name}</span>
<Badge variant={channel.variant}>
{channel.count}
<span className="sr-only"> unread</span>
</Badge>
</div>
))}
</div>
)
}<script setup lang="ts">
import { Badge } from "~~/registry/bases/newt/ui/badge"
const CHANNELS = [
{ name: "announcements", count: 1, variant: "brand" },
{ name: "general", count: 12, variant: "danger" },
{ name: "off-topic", count: 3, variant: "default" },
] as const
</script>
<template>
<!-- A bare number means nothing to a screen reader, so each count says what it counts. -->
<div class="flex w-full max-w-xs flex-col gap-1">
<div
v-for="channel in CHANNELS"
:key="channel.name"
class="flex items-center justify-between gap-3 rounded-sm px-2 py-1.5 text-sm text-newt-text-secondary"
>
<span class="truncate"># {{ channel.name }}</span>
<Badge :variant="channel.variant">
{{ channel.count }}<span class="sr-only"> unread</span>
</Badge>
</div>
</div>
</template>API reference
Badge
variant?"default" | "brand" | "success" | "warning" | "danger"
What the badge is reporting.
"default" | "brand" | "success" | "warning" | "danger""default"dot?boolean
Renders a leading dot in the current text colour.
booleanfalseEvery part also accepts the native attributes of the element it renders, and a className that is merged rather than replaced.
Accessibility
A badge is text, not a control. If it reports something that changes — an unread count, a build status — put it in a container with aria-live="polite" so the change is announced. Never let the colour be the only difference between two states: the words in the badge should differ too.
Tokens
Badge reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-badge.
--newt-radius-full--newt-bg-elevated--newt-text-secondary--newt-mention-text--newt-mention-role