Badge
A small pill for a status, a count, a label or a tag. Renders a `<span>` by default, or whatever Base UI's `render` prop is given, so the same badge can be an anchor without losing its shape.
Preview
Rendered from the story the storybook (a11y) CI gate runs axe against — the preview can't show something that hasn't been verified.
Install
Two equivalent paths — the URL works in any shadcn-CLI setup; the alias works once you've registered @interlace in your components.json.
npx shadcn@latest add https://ds.interlace.tools/r/badge.jsonnpx shadcn@latest add @interlace/badgeBehavior
What this component does — the keyboard path, the measured colour, the text equivalent and the states it can be in. Every figure below is read out of the test or the source that enforces it by scripts/build-behavior-map.mjs, so nothing here can outlive the gate that keeps it true.
Measured contrast
packages/ui/__tests__/theme-contract-lock.test.ts ↗Every semantic colour pair this component's own source uses, measured against the shipped hexes in all 4 theme × scheme combinations. The tightest is info on background at 6.89:1 (harbor · light), against a floor of 4.5:1.
| Pair | interlacelight | interlacedark | harborlight | harbordark | Floor |
|---|---|---|---|---|---|
| info on backgroundtext-info on the page | 8.44:1 | 10.83:1 | 6.89:1 | 13.08:1 | 4.5:1SC 1.4.3 |
| info-foreground on infocopy on a info face | 8.72:1 | 10.98:1 | 7.27:1 | 13.08:1 | 4.5:1SC 1.4.3 |
| info on cardtext-info in a card | 8.72:1 | 10.17:1 | 7.27:1 | 11.86:1 | 4.5:1SC 1.4.3 |
| success on backgroundtext-success on the page | 7.44:1 | 10.16:1 | 7.28:1 | 9.86:1 | 4.5:1SC 1.4.3 |
| destructive on backgroundtext-destructive on the page | 8.05:1 | 10.29:1 | 7.60:1 | 10.03:1 | 4.5:1SC 1.4.3 |
| success-foreground on successcopy on a success face | 7.68:1 | 7.75:1 | 7.68:1 | 7.75:1 | 4.5:1SC 1.4.3 |
| success on cardtext-success in a card | 7.68:1 | 9.54:1 | 7.68:1 | 8.95:1 | 4.5:1SC 1.4.3 |
| warning-foreground on warningcopy on a warning face | 9.07:1 | 7.81:1 | 9.07:1 | 8.65:1 | 4.5:1SC 1.4.3 |
| warning on cardtext-warning in a card | 9.07:1 | 8.54:1 | 9.07:1 | 8.01:1 | 4.5:1SC 1.4.3 |
| destructive-foreground on destructivecopy on a destructive face | 8.31:1 | 10.43:1 | 8.02:1 | 10.03:1 | 4.5:1SC 1.4.3 |
| destructive on cardtext-destructive in a card | 8.31:1 | 9.66:1 | 8.02:1 | 9.09:1 | 4.5:1SC 1.4.3 |
| ring on backgroundfocus ring (SC 2.4.13) | 8.52:1 | 11.63:1 | 8.39:1 | 10.03:1 | 3.0:1SC 1.4.11 |
| primary on backgroundtext-primary on the page | 8.52:1 | 11.63:1 | 8.39:1 | 10.03:1 | 4.5:1SC 1.4.3 |
| warning on backgroundtext-warning on the page | 8.78:1 | 9.09:1 | 8.60:1 | 8.83:1 | 4.5:1SC 1.4.3 |
| ring on cardfocus ring inside a card | 8.80:1 | 10.92:1 | 8.86:1 | 9.10:1 | 3.0:1SC 1.4.11 |
| primary-foreground on primarycopy on a primary face | 8.80:1 | 11.79:1 | 8.86:1 | 10.03:1 | 4.5:1SC 1.4.3 |
| primary on cardtext-primary in a card | 8.80:1 | 10.92:1 | 8.86:1 | 9.10:1 | 4.5:1SC 1.4.3 |
| accent-foreground on accenthover/highlight face | 8.98:1 | 10.46:1 | 8.95:1 | 9.65:1 | 4.5:1SC 1.4.3 |
| secondary-foreground on secondarysecondary button face | 15.58:1 | 14.51:1 | 14.63:1 | 14.04:1 | 4.5:1SC 1.4.3 |
| foreground on backgroundbody copy | 19.02:1 | 16.73:1 | 17.74:1 | 16.19:1 | 4.5:1SC 1.4.3 |
Text pairs are held to 4.5:1 (WCAG 2.2 SC 1.4.3); borders, rings and chart axes to 3:1 (SC 1.4.11 non-text). Bold is the worst cell in the row — the one a brand fork has to keep an eye on.
Runtime contract
packages/ui/vitest.config.ts ↗Where it renders, how narrow it survives, and whether its lines are inside the coverage gate — three answers a consumer needs before the paste, not after the bug.
- Render boundary
server componentRenders during SSR / RSC with no hydration cost. It can be imported from a server component without pulling the page into the client.
- Minimum viewport
none declaredNo width floor: it takes the width it is given. Its container owns the layout question.
- Coverage gate
not in the gateThe 100% gate currently covers
src/charts/**/*.{ts,tsx}andpure cores: day keys, puzzle order, streak arithmetic.and,and, // DataTable: sort order, blanks last, page window, selection.and, // Photo upload: what a file is, what it says about its owner, the plan, the reducer.and, // The account control: names and initials, the return-path check, the reducer, the hook, the menu.and,and,and, // The five pure variant/model modules.and, // Booking: the slot pickerandsrc/patterns/time-slot-model.tsandsrc/patterns/share-image-model.tsandsrc/patterns/{interest-model,commitment-model,session-plan-model,recap-model}.tsandsrc/primitives/{file-model.ts,file-drop.tsx}andsrc/patterns/avatar-upload.tsxands first steps.and, // The 37 components with real render coverage. See the ledger above.and, // Patterns with full render coverage — the same ledger rule: a // file is in at 100 or it is out, and joining is a one-line diff.and, // Effects with full render coverage, on the same rule.and,. This file is outside it — the glob widens in phase 7.2.
History
This component is at v1.6.0, first shipped in @interlace/ui 1.0.0. The version is stamped as a banner into the file the install writes, so the copy in your tree says which one you have — compare it with the number above before deciding whether to re-run the install.
@interlace/ui 2.0.04 entries
- Addedminor
feat(ui): Badge gets
size="sm"(the caption step for dense tag lists and counts) andvariant="scrim"(a translucent face for badges over images and video). One in three Badges in the DS was re-sizing itself withtext-caption tracking-normal …, and article-card hand-built the over-cover look with a seven-class chain; both now use the props.Components - Addedminor
Three additions for content sites. A
--highlight/--highlight-foregroundcolour pair (amber, AAA text in both schemes and in Harbor) with ahighlightButton variant, for the warm call-to-action that is not the brand primary. Badge gainssuccess,warning,infoandhighlighttones. And a--font-headingtoken: Typography h1–h6 and the hero headings read it, it falls back to--font-body, and--font-bodynow follows the app's own--font-sans, so a shadcn app's typeface reaches Interlace components with no setup. Set--font-heading: var(--font-serif)to give headings a serif without touching body text. - Changedpatch
Focus rings are drawn at full strength with one recipe: a 2px ring in
--ringwith a 2px gap in the page colour, the same weight as the preflight outline. Before, most controls drew a 3px ring at 50% or 60% of--ring, which measured 2.5:1 against the light themes (WCAG 1.4.11 asks 3:1), and a destructive button focused at 20%, which measured 1.4:1. Inputs, selects, buttons, tabs, checkboxes, switches, dialogs, sheets, drawers, toasts, menus and the patterns built on them now all focus alike, and the ring sits outside the control instead of over its edge.Components- @interlace/accordion
- @interlace/banner
- @interlace/button
- @interlace/checkbox
- @interlace/combobox
- @interlace/command-palette
- @interlace/dialog
- @interlace/dialogue
- @interlace/dialogue-stepper
- @interlace/drawer
- @interlace/focus-grid
- @interlace/input
- @interlace/otp-field
- @interlace/radio-group
- @interlace/scroll-area
- @interlace/scroller
- @interlace/select
- @interlace/sheet
- @interlace/switch
- @interlace/tabs
- @interlace/textarea
- @interlace/toast
- @interlace/toolbar
- @interlace/topbar-menu
- @interlace/wordmark
- Changedpatch
fix(ui): A loading Card or Badge keeps its
data-testidand ARIA. Theloadingbranch rendered a Skeleton with onlyclassName, so an E2E selector or anaria-labelvanished for exactly as long as the content was loading. Card forwards all its props; Badge forwardsdata-*,aria-*andid(the rest are<span>props and the skeleton is a<div>).Components
@interlace/ui 1.1.01 entry
- Changedpatch
Six defects found by upgrading a real consumer, plus five found by reading the components closely enough to document them. **
Meteors' glow never painted.** It readvar(--color-meteor-glow)while itscssVarsdeclare--meteor-glow;--color-*is the Tailwind@themenamespace and onlycssVars.themepopulates it, so the wholebox-shadowwas invalid at computed-value time. **This was broken only for registry consumers** — our own docs site hand-declares the--color-form. **ArticleCardcropped 28% off every cover.**h-44is 176px; at a ~302px tile that is a 1.72:1 box against a 2.381:1 image. Nowaspect-[1000/420]— the ratio the card already declared on its<img>. It also gains arenderImageslot, because every Next.js consumer was re-patching the same line to usenext/imageand the design system cannot depend on it. **BorderBeamandStarsBackgroundhad noaria-hiddenat all** — six purely decorative nodes a screen reader walked. **CloudParticlesdefaultedbodyColortocurrentColor**, painting volumetric clouds in the inherited text colour. **NumberTickergainsnotation**, because six-figure metrics overflow a tile at 320px. Also:SheetComposeandDialogComposeeach mounted a second backdrop, so a composed dialog dimmed the page twice as much as the hand-composed tree the docs show;AccordiondroppedclassNameon the animated Panel;Tooltipaccepteddelayand discarded it;PopoverAnchorwas a second trigger. **useReducedMotionwas one frame late.** The canonicaluseState(false)plus effect returnsfalseon the first render, so every gated component painted one frame of exactly the motion the user turned off.useSyncExternalStorereads during render and closes that on client renders; on hydration the server cannot know the preference, which is what the stylesheet reset is for.Badgedrops'use client'— verified with a real server-component build.
@interlace/ui 1.0.01 entry
- Addedminor
The component floor reaches every tier: form, overlay, navigation and display primitives were modelled to the portable 26-rule floor with skeletons, locked breakpoints, and AA contrast measured per composite rather than eyeballed.
Components- @interlace/input
- @interlace/textarea
- @interlace/select
- @interlace/checkbox
- @interlace/radio-group
- @interlace/switch
- @interlace/slider
- @interlace/number-field
- @interlace/form
- @interlace/label
- @interlace/dialog
- @interlace/alert-dialog
- @interlace/sheet
- @interlace/popover
- @interlace/tooltip
- @interlace/hover-card
- @interlace/dropdown-menu
- @interlace/context-menu
- @interlace/tabs
- @interlace/accordion
- @interlace/collapsible
- @interlace/breadcrumb
- @interlace/pagination
- @interlace/toast
- @interlace/card
- @interlace/avatar
- @interlace/alert
- @interlace/separator
- @interlace/progress
- @interlace/skeleton
Import
2 named exports — pull the parts you need.
import { Badge, badgeVariants } from '@/components/ui/badge';Anatomy
Extracted from the primitive's JSDoc header. The source is the only documentation that can't drift.
Badge (span by default, or the `render` element)
└─ children (text and/or an svg, sized to size-3 here)Variants
Closed prop unions enforced by class-variance-authority. See Storybook's Variants story for the rendered matrix.
- variant
- defaultdefault
- success
- warning
- info
- highlight
- secondary
- destructive
- outline
- ghost
- link
- scrim
- size
- defaultdefault
- sm
API reference
Parsed from the type declarations in the source — the same file the install writes into your tree, so this table can't drift from the component you get.
BadgeProps
Also accepts every <span> attribute. Plus the variant props listed above.
| Prop | Type | Description |
|---|---|---|
| render | useRender.RenderProp | — |
| loading | boolean | When true, render a `<Skeleton variant="badge" />` in place of the normal Badge surface. Shape-matched placeholder (h-5 w-16 rounded-full) so the row layout doesn't shift on data arrival. |
Skeleton
Pass loading and the component renders a shape-matched <Skeleton /> in its own place — same box, so nothing reflows when the data lands. Below is the same story with loading={true}.
<Badge loading={isPending} />Accessibility
Every story for this component is rendered headlessly and checked with axe-core (wcag2aa, wcag22aa, best-practice, ACT) on every PR. That gate has no continue-on-error, so what ships has zero known violations.
What follows is what static analysis can see. Axe cannot press a key and never sees an overlay open, so the operable-without-a-mouse claim lives in Behavior instead, where the keyboard path is replayed step by step.
- Focus + keyboard behaviour
- Owned by @base-ui/react/use-render — focus trapping, dismissal and typeahead come from the headless primitive, not from us.
- Focus ring (WCAG 2.2 SC 2.4.13)
- Drawn by the component's own focus-visible classes, so it holds with or without the opt-in preflight.
- Reduced motion
- No animation to gate.
- ARIA in the source
aria-invalid
Examples
4 more states from the same story file.
R-rule compliance
Every primitive in @interlace/ui models to the portable 26-rule floor enforced by the componentApi ESLint preset. The cells below pin exactly where each rule applies in this file.
| Rule | Concept | Where |
|---|---|---|
| R4 | Extends native el | `React.ComponentProps<'span'>` |
| R6 | data-slot + data-variant on root | `'data-slot': 'badge'`, `'data-variant': variant` |
| R7 | cva + cn + ...rest | `cn(badgeVariants({ variant }), className)` + `...props` |
| R8 | Enum for variant | default / success / warning / info / highlight / secondary / destructive / outline / ghost / link |
| R10 | Composition seam | `render` — Base UI's `useRender`, not an `as` prop |
| R19 | Tokens only | `bg-primary`, `bg-secondary`, `bg-destructive`, `bg-accent` |
| R20 | AA contrast | every variant composited by `composite-contrast-lock` |
| R25 | Client component | Not required — server component, see the note above |
Dependencies
- Base UI primitive
- @base-ui/react/use-render
- Lucide icons
- none
- NPM dependencies
@base-ui/reactclass-variance-authority
- Registry dependencies
Source
The full implementation — components/ui/badge.tsx once installed.
import * as React from 'react';
// @interlace/badge v1.6.0 — Interlace design system.
// Docs, props and live preview: https://ds.interlace.tools/c/badge
// What changed since: https://ds.interlace.tools/c/badge#history
// Generated banner — keep it, the upgrade diff reads this version.
/**
* @interlace/ui — Badge
*
* A small pill for a status, a count, a label or a tag. Renders a `<span>` by
* default, or whatever Base UI's `render` prop is given, so the same badge can
* be an anchor without losing its shape.
*
* Ten variants, and every one that names a text colour also paints an opaque
* surface under it — see the rule below.
*
* ## Anatomy
*
* Badge (span by default, or the `render` element)
…200 more lines…Registry JSON
The raw registry record — what the shadcn CLI fetches.