# Introduction
Accessible React components on Base UI and Tailwind CSS. You copy each one into your project with the CLI, and from then on the code is yours to change.
## What it is
YolkUI is a personal project, and an exploration more than a product. I wanted to see how far a small set of components could go if every detail got real attention: the focus ring, a disabled button that can still tell you why it's off, a menu that opens on the correct side in Arabic. I share it here in case it helps you too.
## How it works
You don't install YolkUI as a package. The CLI copies a component's source into your project, together with any component it builds on, and the file is yours from that moment. Change the markup, the classes or the behavior however you like. Nothing waits upstream to overwrite your edits. The components so far run from [Accordion](https://yolkui.com/docs/components/accordion) to [Tooltip](https://yolkui.com/docs/components/tooltip), and each one has a page with examples you can copy.
```tsx
npx @yolkui/cli add button
```
## What it's built on
[Base UI](https://base-ui.com) does the hard part: keyboard support, focus and the ARIA attributes a screen reader needs. Its team has done careful, patient work there, and YolkUI leans on it everywhere. [Tailwind CSS](https://tailwindcss.com) v4 draws the look through a small set of color, radius and type tokens, which [Theming](https://yolkui.com/docs/theming) explains. A component file stands on its own and needs no icon library.
## Works with shadcn/ui
I learned a lot from [shadcn/ui](https://ui.shadcn.com), and YolkUI follows its conventions on purpose. The parts, the prop names and the theme tokens match, so a shadcn theme pastes in and shadcn components sit next to these ones. You can even add a YolkUI component with the shadcn CLI. The one difference you'll notice is the radius scale, and [Theming](https://yolkui.com/docs/theming#shadcn-themes) shows how the two line up.
```tsx
npx shadcn add https://yolkui.com/r/button.json
```
## What I check on every component
Before a component goes up, it has to do all of this, and [Accessibility](https://yolkui.com/docs/accessibility) covers each check in detail:
- Work with a keyboard alone, and say what it is to a screen reader.
- Look right in light and dark, with every text color at WCAG AA contrast in both.
- Mirror itself in right to left languages such as Arabic and Hebrew.
- Stay visible in Windows High Contrast mode.
- Keep a disabled control in the Tab order, so a tooltip can explain why it's off.
- Pass its own tests, including an automated accessibility check.
## Made to work with AI
The code lives in your project, so an AI assistant can read it and change it like any other file. Every page also has a Copy page button that gives you the whole page as Markdown, ready to paste into a chat. AI tools can read [llms.txt](https://yolkui.com/llms.txt), a list of every page, or [llms-full.txt](https://yolkui.com/llms-full.txt), every page in one file.
## Requirements
React 19.2 or newer and Tailwind CSS v4, in a Next.js or Vite project. It runs in current versions of Chrome, Edge, Firefox and Safari. [Installation](https://yolkui.com/docs/installation) walks you through the setup.
## Questions
### Is YolkUI free?
Yes. YolkUI uses the MIT license, so you can use it in personal and commercial projects.
### Does it work with shadcn/ui?
Yes. The theme tokens, parts and prop names match shadcn/ui, so a shadcn theme pastes in and shadcn components sit next to YolkUI ones. [Works with shadcn/ui](#shadcn) has the details.
### Do I need an icon library?
No. The few icons a component needs, such as a check mark or a chevron, live inside its file. For your own icons any library works, and the examples use [Lucide](https://lucide.dev).
### How do I get updates?
Run the add command again. The CLI asks before it replaces a file you already have, so your own changes stay put until you say yes.
### Can I use it in production?
Yes, but read the code before you ship it, since YolkUI is still young. I use it on this site, and every component has its own tests.
## Who makes it
I'm [Antoni Botev](https://antonibotev.com), a product designer. I design products full of data and build them in code, and YolkUI is where I try out ideas about components before I use them in real work. You'll find me on [X](https://x.com/Sinote), [GitHub](https://github.com/antonibotev) and [LinkedIn](https://www.linkedin.com/in/antonibotev/).
---
# Installation
Install YolkUI in a Next.js or Vite project with Tailwind CSS v4. Run init once, then add any component with one command and change its code as you like.
## Requirements
React 19.2 or newer, Tailwind CSS v4 and an import alias such as `@/`. YolkUI ships TypeScript files.
## Next.js
A new Next.js app comes with Tailwind CSS v4 and the `@/` alias, so `init` needs nothing else. In an existing app, run `init` in its folder.
```bash
npx create-next-app@latest my-app --yes
cd my-app
npx @yolkui/cli init
```
## Vite
Set up Tailwind CSS v4 first with [its Vite guide](https://tailwindcss.com/docs/installation/using-vite). Then add the `@/` alias to `tsconfig.app.json` and `vite.config.ts`, and run `init`.
```tsx
// tsconfig.app.json, in compilerOptions
"baseUrl": ".",
"paths": { "@/*": ["./src/*"] }
// vite.config.ts
import path from "node:path"
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: { "@": path.resolve(__dirname, "./src") },
},
})
```
## What init changes
`init` finds your CSS file and your import alias, adds the theme tokens to your CSS, writes `components.json` and adds `cn()` to `lib/utils.ts`. The rest of your CSS stays as it is. [CLI](https://yolkui.com/docs/cli#init) lists every step, and [Theming](https://yolkui.com/docs/theming) explains the tokens.
## Add a component
Each component lands in `components/ui`, together with the components it uses. Import it from there, and change the file however you like. Every component page has its own install command, starting with [Button](https://yolkui.com/docs/components/button).
```bash
npx @yolkui/cli add button
```
```tsx
import { Button } from "@/components/ui/button"
export default function Page() {
return
}
```
## Without the CLI
Install the two packages `cn()` uses and add it to `lib/utils.ts`. Then paste the [full theme](https://yolkui.com/docs/theming#full-theme) into your CSS file. After that, the Manual tab on each component page lists the packages it needs and the file to copy.
```bash
npm install clsx tailwind-merge
```
```ts
import { clsx, type ClassValue } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";
/**
* tailwind-merge only knows Tailwind's own font sizes. Our semantic type roles
* (`text-label`, `text-h1`, …) look like colours to it, so it drops them the
* moment a real colour follows — `cn("text-label", "text-primary-foreground")`
* silently returned only the colour. Naming the roles here keeps both.
*
* Every role added to `@theme` in globals.css must be listed.
*/
const twMerge = extendTailwindMerge({
extend: {
classGroups: {
"font-size": [
{
text: [
"display",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"body-lg",
"body",
"body-sm",
"label",
"label-sm",
"caption",
"overline",
"overline-mono",
"code",
],
},
],
},
},
});
/** Merge class names, letting later Tailwind classes override earlier ones. */
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
```
## Dark mode
The dark theme turns on under a `dark` class or `data-theme="dark"` on any parent element, usually ``, so [next-themes](https://github.com/pacocoursey/next-themes) works as it is. Set it before the first paint, or the page flashes light for a moment.
---
# Theming
Color tokens as CSS variables for light and dark mode, with the contrast of every pair. Change a color, add one, set radius and fonts, or paste a shadcn theme.
## How the colors work
Every color comes as a pair: a fill and the text on it, such as `--primary` and `--primary-foreground`. Components use only these names, never a color of their own, so one value changes everything that uses it. Each value points at a color of Tailwind's palette, and the dark theme sets the same names again. `@theme inline` turns each one into a utility, `bg-primary` or `text-primary-foreground`, as [Tailwind's theme variables](https://tailwindcss.com/docs/theme) explain.
```tsx
:root {
--primary: var(--color-gray-900);
--primary-foreground: var(--color-gray-50);
}
.dark,
[data-theme="dark"] {
--primary: var(--color-gray-50);
--primary-foreground: var(--color-gray-900);
}
@theme inline {
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
}
```
## Colors
Every token, in light and in dark. The number under each swatch is its contrast: text on its fill needs 4.5:1, a focus ring, a field border or a chart mark 3:1 on the page. Every pair passes WCAG AA in both themes, and a test checks it whenever a value changes. Fills also have `-hover`, `-active` and `-separator` states, and a few components have tokens of their own (`--switch-*`, `--segment-*`, `--toggle-active`); they are in the full theme at the end of this page.
| Token | Text on it | Used for |
| --- | --- | --- |
| `--background` | `--foreground` | The page and the text on it. |
| `--card` | `--card-foreground` | Card and Alert. A step above the page in dark. |
| `--popover` | `--popover-foreground` | Everything that floats: menus, Select, Combobox, Popover, Dialog, Toast. |
| `--muted` | `--muted-foreground` | Quiet fills (a read-only field, the Progress track); its text is the secondary text everywhere. |
| `--primary` | `--primary-foreground` | The default Button, a checked Checkbox, Radio and Switch, the selected day, the Slider. |
| `--secondary` | `--secondary-foreground` | The secondary Button, a neutral Badge, the Avatar fallback. |
| `--accent` | `--accent-foreground` | Hover on anything without a fill of its own: outline and ghost buttons, menu items, Toggle. |
| `--accent-primary` | `--accent-primary-foreground` | The blue Button (variant="accent"), for an action that should stand out. |
| `--soft` | `--soft-foreground` | The raised surface: soft buttons, fields, the selected tab. |
| `--brand` | `--brand-foreground` | The Yolk color. Small highlights only, as a fill: as text it is too light. |
| `--success` | `--success-foreground` | Done, saved, online. |
| `--info` | `--info-foreground` | Something to know, with nothing wrong. |
| `--warning` | `--warning-foreground` | Needs attention soon. |
| `--destructive` | `--destructive-foreground` | Errors, an invalid field, actions that delete. |
| `--success-subtle` | `--success-subtle-foreground` | A quiet tint for dense lists: a subtle Badge, an Alert. |
| `--info-subtle` | `--info-subtle-foreground` | The quiet tint of info. |
| `--warning-subtle` | `--warning-subtle-foreground` | The quiet tint of warning. |
| `--destructive-subtle` | `--destructive-subtle-foreground` | The quiet tint of destructive. |
| `--accent-subtle` | `--accent-subtle-foreground` | The quiet tint of the blue. |
| `--brand-subtle` | `--brand-subtle-foreground` | The quiet tint of the brand. |
| `--border` | | Lines and dividers: separators, Accordion, Tabs. |
| `--hairline` | | The 1px edge of cards and popups, translucent so it reads on any fill. |
| `--input` | | A field's border in shadcn components; YolkUI fields draw the soft ring instead. |
| `--ring` | | The focus outline on every control. |
| `--chart-1` | | Series 1, blue. Each hue stands 3:1 off the page. |
| `--chart-2` | | Series 2, emerald. Each hue stands 3:1 off the page. |
| `--chart-3` | | Series 3, amber. Each hue stands 3:1 off the page. |
| `--chart-4` | | Series 4, rose. Each hue stands 3:1 off the page. |
| `--chart-5` | | Series 5, violet. Each hue stands 3:1 off the page. |
| `--sidebar` | `--sidebar-foreground` | An app sidebar, a step off the page. |
| `--sidebar-primary` | `--sidebar-primary-foreground` | The current item. |
| `--sidebar-accent` | `--sidebar-accent-foreground` | Hover on an item. |
| `--sidebar-border` | | Its edge and dividers. |
| `--sidebar-ring` | | Focus inside it. |
## Dark mode
The dark theme turns on under a `dark` class or `data-theme="dark"` on any parent element, usually ``, so [next-themes](https://github.com/pacocoursey/next-themes) works as it is. Set it before the first paint, from a small script in `
`, or the page flashes light for a moment.
```tsx
// next-themes
```
## A dark section on a light page
`data-theme="dark"` works on any element, not only ``: everything inside it takes the dark tokens. YolkUI doesn't support the opposite, a light section on a dark page: components draw some details with Tailwind's `dark:` variant, which follows the dark parent.
```tsx
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
/** A dark section on a light page: data-theme on the section, not on . */
export default function ThemingDarkSection() {
return (
New
Dark inside, light around it
Every component in this section takes the dark tokens.
)
}
```
## Radius
One value, `--radius`, rounds everything. The steps are Tailwind's, written as multiples of it, so at the default 0.5rem the numbers match Tailwind's docs and a new value re-rounds every component in proportion.
| Token | Of --radius | Default | Used for |
| --- | --- | --- | --- |
| --radius-xs | ×0.25 | 2px | Small marks inside a component |
| --radius-sm | ×0.5 | 4px | Menu and list rows, Checkbox, chips |
| --radius-md | ×0.75 | 6px | Badge, a Button at xs, Tooltip |
| --radius-lg | ×1 | 8px | Button, Input, Select, every popup |
| --radius-xl | ×1.5 | 12px | Card, Toast, Toolbar |
| --radius-2xl | ×2 | 16px | Dialog, Alert Dialog |
| --radius-3xl | ×3 | 24px | — |
| --radius-4xl | ×4 | 32px | — |
```tsx
:root {
--radius: 0.75rem; /* controls 12, cards 18 */
}
```
## Fonts
Components use `font-sans` for text and `font-mono` for code and numbers, never a font's name, so a project keeps its own. Point the two at your fonts in `@theme inline`.
```tsx
@theme inline {
--font-sans: var(--font-inter);
--font-mono: var(--font-geist-mono);
}
```
## Change a color
Set the token in both blocks. Here the blue action becomes green. Keep the text on it at 4.5:1: white needs a `-600` or darker step.
```tsx
:root {
--accent-primary: var(--color-emerald-700);
}
.dark,
[data-theme="dark"] {
--accent-primary: var(--color-emerald-600);
}
```
## Add a color
Define the pair in both themes, then map it in `@theme inline`. `bg-highlight` and `text-highlight-foreground` work from then on.
```tsx
:root {
--highlight: var(--color-violet-600);
--highlight-foreground: var(--color-white);
}
.dark,
[data-theme="dark"] {
--highlight: var(--color-violet-400);
--highlight-foreground: var(--color-violet-950);
}
@theme inline {
--color-highlight: var(--highlight);
--color-highlight-foreground: var(--highlight-foreground);
}
```
```tsx
New
```
## Themes from shadcn/ui
The token names and meanings are shadcn/ui's, so a [shadcn theme](https://ui.shadcn.com/themes) pastes in over ours and its components drop in. One difference: our radius steps are Tailwind's, so a theme's `--radius: 0.625rem` rounds controls to 10px, and a pasted shadcn component's `rounded-md` comes out 6px beside our 8px controls.
## The full theme
Every token above in one file, as the CLI's [init command](https://yolkui.com/docs/cli#init) adds it to your CSS. It leaves the rest of your file as it is. To set it up by hand, follow [Without the CLI](https://yolkui.com/docs/installation#without-the-cli).
```css
@import "tailwindcss";
@custom-variant dark (&:where([data-theme="dark"], [data-theme="dark"] *, .dark, .dark *));
:root,
[data-theme="light"] {
color-scheme: light;
--background: var(--color-white);
--foreground: var(--color-gray-950);
--card: var(--color-white);
--card-foreground: var(--color-gray-950);
--popover: var(--color-white);
--popover-foreground: var(--color-gray-950);
--primary: var(--color-gray-900);
--primary-foreground: var(--color-gray-50);
--primary-hover: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700));
--primary-active: var(--color-gray-700);
--primary-separator: var(--color-gray-700);
--secondary: var(--color-gray-100);
--secondary-foreground: var(--color-gray-900);
--secondary-hover: color-mix(in oklab, var(--color-gray-100) 25%, var(--color-gray-200));
--secondary-active: color-mix(in oklab, var(--color-gray-200), var(--color-gray-300));
--secondary-separator: var(--color-gray-200);
--segment-track: var(--secondary);
--segment-indicator: var(--soft);
--switch-track: var(--border);
--switch-ring: var(--hairline);
--switch-thumb: var(--soft);
--switch-thumb-checked: var(--soft);
--switch-thumb-ring: var(--soft-ring-hover);
--switch-thumb-edge: var(--soft-edge-hover);
--switch-track-hover: var(--color-gray-300);
--switch-track-active: color-mix(in oklab, var(--color-gray-300), var(--color-gray-400));
--switch-on-hover: var(--primary-active);
--switch-on-active: color-mix(in oklab, var(--color-gray-700), var(--color-gray-600));
--toggle-active: var(--color-gray-300);
--accent: var(--color-gray-100);
--accent-foreground: var(--color-gray-950);
--accent-active: color-mix(in oklab, var(--color-gray-100) 40%, var(--color-gray-200));
--muted: var(--color-gray-100);
--muted-foreground: var(--color-gray-600);
--accent-primary: var(--color-blue-700);
--accent-primary-foreground: var(--color-white);
--accent-primary-hover: color-mix(in oklab, var(--color-blue-700), var(--color-blue-800));
--accent-primary-active: var(--color-blue-800);
--accent-soft-ring: --alpha(var(--color-blue-950) / 50%);
--accent-soft-edge: --alpha(var(--color-blue-950) / 75%);
--accent-primary-separator: --alpha(var(--color-white) / 15%);
--brand: var(--color-amber-500);
--brand-foreground: var(--color-gray-950);
--brand-hover: color-mix(in oklab, var(--color-amber-500), var(--color-amber-400));
--brand-active: var(--color-amber-400);
--brand-soft-ring: var(--soft-ring);
--brand-soft-edge: var(--soft-edge);
--brand-separator: var(--brand-soft-ring);
--destructive: var(--color-rose-700);
--destructive-foreground: var(--color-white);
--destructive-hover: color-mix(in oklab, var(--color-rose-700), var(--color-rose-800));
--destructive-active: var(--color-rose-800);
--destructive-separator: var(--color-rose-600);
--success: var(--color-emerald-700);
--success-foreground: var(--color-white);
--success-hover: color-mix(in oklab, var(--color-emerald-700), var(--color-emerald-800));
--warning: var(--color-orange-500);
--warning-foreground: var(--color-orange-950);
--warning-hover: color-mix(in oklab, var(--color-orange-500), var(--color-orange-400));
--info: var(--color-indigo-600);
--info-foreground: var(--color-white);
--info-hover: color-mix(in oklab, var(--color-indigo-600), var(--color-indigo-700));
--brand-subtle: var(--color-amber-100);
--brand-subtle-foreground: var(--color-amber-900);
--success-subtle: var(--color-emerald-100);
--success-subtle-foreground: var(--color-emerald-800);
--warning-subtle: var(--color-orange-100);
--warning-subtle-foreground: var(--color-orange-800);
--info-subtle: var(--color-indigo-100);
--info-subtle-foreground: var(--color-indigo-800);
--destructive-subtle: var(--color-rose-100);
--destructive-subtle-foreground: var(--color-rose-800);
--accent-subtle: var(--color-blue-100);
--accent-subtle-foreground: var(--color-blue-800);
--border: var(--color-gray-200);
--outline-border: var(--border);
--outline-fill: var(--background);
--outline-fill-active: var(--accent-active);
--input: var(--color-gray-500);
--ring: var(--color-gray-900);
--soft: var(--color-white);
--soft-foreground: var(--color-gray-800);
--soft-hover: color-mix(in oklab, var(--color-gray-50), var(--color-gray-100));
--soft-active: color-mix(in oklab, var(--color-gray-100), var(--color-gray-200));
--soft-edge: --alpha(var(--color-gray-950) / 16%);
--soft-edge-offset: -1px;
--soft-ring: --alpha(var(--color-gray-950) / 15%);
--soft-lift: --alpha(var(--color-gray-950) / 4%);
--soft-ring-hover: --alpha(var(--color-gray-950) / 22%);
--soft-edge-hover: --alpha(var(--color-gray-950) / 22%);
--input-action: color-mix(in oklab, var(--color-gray-400), var(--color-gray-500));
--hairline: --alpha(var(--color-gray-950) / 12%);
--popover-shadow: 0 12px 28px -4px --alpha(var(--color-gray-900) / 12%),
0 2px 6px -1px --alpha(var(--color-gray-900) / 6%);
--dialog-shadow: 0 16px 40px -8px --alpha(var(--color-gray-900) / 20%),
0 2px 6px -1px --alpha(var(--color-gray-900) / 6%);
--chart-1: var(--color-blue-600);
--chart-2: var(--color-emerald-600);
--chart-3: var(--color-amber-600);
--chart-4: var(--color-rose-600);
--chart-5: var(--color-violet-600);
--sidebar: var(--color-gray-50);
--sidebar-foreground: var(--color-gray-950);
--sidebar-primary: var(--color-gray-900);
--sidebar-primary-foreground: var(--color-gray-50);
--sidebar-accent: var(--color-gray-100);
--sidebar-accent-foreground: var(--color-gray-900);
--sidebar-border: var(--color-gray-200);
--sidebar-ring: var(--color-gray-900);
--radius: 0.5rem;
}
.dark,
[data-theme="dark"] {
color-scheme: dark;
--background: var(--color-gray-950);
--foreground: var(--color-gray-50);
--card: var(--color-gray-900);
--card-foreground: var(--color-gray-50);
--popover: var(--color-gray-900);
--popover-foreground: var(--color-gray-50);
--primary: var(--color-gray-50);
--primary-foreground: var(--color-gray-900);
--primary-hover: color-mix(in oklab, var(--color-gray-200), var(--color-gray-300));
--primary-active: color-mix(in oklab, var(--color-gray-300), var(--color-gray-400));
--primary-separator: var(--color-gray-200);
--secondary: color-mix(in oklab, var(--color-gray-900), var(--color-gray-800));
--secondary-foreground: var(--color-gray-50);
--secondary-hover: var(--color-gray-800);
--secondary-active: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700));
--secondary-separator: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700));
--segment-track: var(--muted);
--segment-indicator: color-mix(in oklab, var(--muted), var(--soft-active));
--switch-ring: color-mix(in oklab, var(--soft-ring) 70%, transparent);
--switch-thumb: var(--color-gray-600);
--switch-thumb-checked: var(--primary-foreground);
--switch-thumb-ring: var(--soft-ring-hover);
--switch-thumb-edge: --alpha(var(--color-white) / 20%);
--switch-track-hover: var(--secondary-active);
--switch-track-active: var(--soft-active);
--switch-on-hover: var(--primary-hover);
--switch-on-active: var(--primary-active);
--toggle-active: var(--soft-active);
--accent: color-mix(in oklab, var(--color-gray-900), var(--color-gray-800));
--accent-foreground: var(--color-gray-50);
--accent-active: var(--color-gray-800);
--muted: var(--color-gray-800);
--muted-foreground: var(--color-gray-400);
--accent-primary: var(--color-blue-600);
--accent-primary-foreground: var(--color-white);
--accent-primary-hover: color-mix(in oklab, var(--color-blue-600), var(--color-blue-700));
--accent-primary-active: var(--color-blue-700);
--accent-soft-ring: --alpha(var(--color-white) / 15%);
--accent-soft-edge: --alpha(var(--color-white) / 10%);
--brand-soft-ring: --alpha(var(--color-white) / 32%);
--brand-soft-edge: --alpha(var(--color-white) / 20%);
--destructive: var(--color-rose-400);
--destructive-foreground: var(--color-rose-950);
--destructive-hover: color-mix(in oklab, var(--color-rose-400), var(--color-rose-300));
--destructive-active: var(--color-rose-300);
--success: var(--color-emerald-400);
--success-foreground: var(--color-emerald-950);
--success-hover: color-mix(in oklab, var(--color-emerald-400), var(--color-emerald-300));
--warning: var(--color-orange-400);
--warning-foreground: var(--color-orange-950);
--warning-hover: color-mix(in oklab, var(--color-orange-400), var(--color-orange-300));
--info: var(--color-indigo-400);
--info-foreground: var(--color-indigo-950);
--info-hover: color-mix(in oklab, var(--color-indigo-400), var(--color-indigo-300));
--brand-subtle: var(--color-amber-950);
--brand-subtle-foreground: var(--color-amber-300);
--success-subtle: var(--color-emerald-950);
--success-subtle-foreground: var(--color-emerald-300);
--warning-subtle: var(--color-orange-950);
--warning-subtle-foreground: var(--color-orange-300);
--info-subtle: var(--color-indigo-950);
--info-subtle-foreground: var(--color-indigo-300);
--destructive-subtle: var(--color-rose-950);
--destructive-subtle-foreground: var(--color-rose-300);
--accent-subtle: var(--color-blue-950);
--accent-subtle-foreground: var(--color-blue-300);
--border: var(--color-gray-800);
--outline-border: var(--secondary-separator);
--outline-fill: transparent;
--outline-fill-active: var(--secondary-active);
--input: var(--color-gray-500);
--ring: var(--color-gray-300);
--soft: var(--color-gray-800);
--soft-foreground: var(--color-gray-200);
--soft-hover: color-mix(in oklab, var(--color-gray-800), var(--color-gray-700));
--soft-active: var(--color-gray-700);
--soft-edge: --alpha(var(--color-white) / 14%);
--soft-edge-offset: 1px;
--soft-ring: --alpha(var(--color-white) / 11%);
--soft-lift: --alpha(var(--color-black) / 30%);
--soft-ring-hover: --alpha(var(--color-white) / 19%);
--soft-edge-hover: --alpha(var(--color-white) / 12%);
--hairline: --alpha(var(--color-white) / 14%);
--popover-shadow: 0 12px 32px -6px --alpha(var(--color-black) / 50%);
--dialog-shadow: 0 16px 48px -8px --alpha(var(--color-black) / 60%);
--chart-1: var(--color-blue-400);
--chart-2: var(--color-emerald-400);
--chart-3: var(--color-amber-400);
--chart-4: var(--color-rose-400);
--chart-5: var(--color-violet-400);
--sidebar: var(--color-gray-900);
--sidebar-foreground: var(--color-gray-50);
--sidebar-primary: var(--color-gray-50);
--sidebar-primary-foreground: var(--color-gray-900);
--sidebar-accent: var(--color-gray-800);
--sidebar-accent-foreground: var(--color-gray-50);
--sidebar-border: var(--color-gray-800);
--sidebar-ring: var(--color-gray-300);
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
--color-card-foreground: var(--card-foreground);
--color-popover: var(--popover);
--color-popover-foreground: var(--popover-foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-primary-hover: var(--primary-hover);
--color-primary-active: var(--primary-active);
--color-primary-separator: var(--primary-separator);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-secondary-hover: var(--secondary-hover);
--color-secondary-active: var(--secondary-active);
--color-secondary-separator: var(--secondary-separator);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-accent-active: var(--accent-active);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent-primary: var(--accent-primary);
--color-accent-primary-foreground: var(--accent-primary-foreground);
--color-accent-primary-hover: var(--accent-primary-hover);
--color-accent-primary-active: var(--accent-primary-active);
--color-accent-soft-ring: var(--accent-soft-ring);
--color-accent-soft-edge: var(--accent-soft-edge);
--color-accent-primary-separator: var(--accent-primary-separator);
--color-brand: var(--brand);
--color-brand-foreground: var(--brand-foreground);
--color-brand-hover: var(--brand-hover);
--color-brand-active: var(--brand-active);
--color-brand-soft-ring: var(--brand-soft-ring);
--color-brand-soft-edge: var(--brand-soft-edge);
--color-brand-separator: var(--brand-separator);
--color-destructive: var(--destructive);
--color-destructive-foreground: var(--destructive-foreground);
--color-destructive-hover: var(--destructive-hover);
--color-destructive-active: var(--destructive-active);
--color-destructive-separator: var(--destructive-separator);
--color-success: var(--success);
--color-success-foreground: var(--success-foreground);
--color-success-hover: var(--success-hover);
--color-warning: var(--warning);
--color-warning-foreground: var(--warning-foreground);
--color-warning-hover: var(--warning-hover);
--color-info: var(--info);
--color-info-foreground: var(--info-foreground);
--color-info-hover: var(--info-hover);
--color-brand-subtle: var(--brand-subtle);
--color-brand-subtle-foreground: var(--brand-subtle-foreground);
--color-success-subtle: var(--success-subtle);
--color-success-subtle-foreground: var(--success-subtle-foreground);
--color-warning-subtle: var(--warning-subtle);
--color-warning-subtle-foreground: var(--warning-subtle-foreground);
--color-info-subtle: var(--info-subtle);
--color-info-subtle-foreground: var(--info-subtle-foreground);
--color-destructive-subtle: var(--destructive-subtle);
--color-destructive-subtle-foreground: var(--destructive-subtle-foreground);
--color-accent-subtle: var(--accent-subtle);
--color-accent-subtle-foreground: var(--accent-subtle-foreground);
--color-border: var(--border);
--color-outline-border: var(--outline-border);
--color-segment-track: var(--segment-track);
--color-segment-indicator: var(--segment-indicator);
--color-switch-track: var(--switch-track);
--color-switch-ring: var(--switch-ring);
--color-switch-thumb: var(--switch-thumb);
--color-switch-thumb-checked: var(--switch-thumb-checked);
--color-toggle-active: var(--toggle-active);
--color-outline-fill: var(--outline-fill);
--color-outline-fill-active: var(--outline-fill-active);
--color-input: var(--input);
--color-ring: var(--ring);
--color-soft: var(--soft);
--color-soft-foreground: var(--soft-foreground);
--color-soft-hover: var(--soft-hover);
--color-soft-active: var(--soft-active);
--color-soft-edge: var(--soft-edge);
--color-soft-lift: var(--soft-lift);
--color-soft-ring: var(--soft-ring);
--color-soft-ring-hover: var(--soft-ring-hover);
--color-soft-edge-hover: var(--soft-edge-hover);
--color-input-action: var(--input-action);
--color-hairline: var(--hairline);
--color-chart-1: var(--chart-1);
--color-chart-2: var(--chart-2);
--color-chart-3: var(--chart-3);
--color-chart-4: var(--chart-4);
--color-chart-5: var(--chart-5);
--color-sidebar: var(--sidebar);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-ring: var(--sidebar-ring);
--shadow-soft: 0 1px 3px 0 var(--soft-lift), inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge),
inset 0 0 0 1px var(--soft-ring);
--shadow-accent-soft: 0 1px 3px 0 var(--soft-lift),
inset 0 var(--soft-edge-offset) 0 0 var(--accent-soft-edge), inset 0 0 0 1px var(--accent-soft-ring);
--shadow-brand-soft: 0 1px 3px 0 var(--soft-lift),
inset 0 var(--soft-edge-offset) 0 0 var(--brand-soft-edge), inset 0 0 0 1px var(--brand-soft-ring);
--shadow-soft-hover: 0 1px 3px 0 var(--soft-lift),
inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge-hover), inset 0 0 0 1px var(--soft-ring-hover);
--shadow-soft-invalid: 0 1px 3px 0 var(--soft-lift),
inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge), inset 0 0 0 1px var(--destructive);
--shadow-soft-invalid-hover: 0 1px 3px 0 var(--soft-lift),
inset 0 var(--soft-edge-offset) 0 0 var(--soft-edge-hover), inset 0 0 0 1px var(--destructive);
--radius-xs: calc(var(--radius) * 0.25);
--radius-sm: calc(var(--radius) * 0.5);
--radius-md: calc(var(--radius) * 0.75);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) * 1.5);
--radius-2xl: calc(var(--radius) * 2);
--radius-3xl: calc(var(--radius) * 3);
--radius-4xl: calc(var(--radius) * 4);
--text-display: var(--text-5xl);
--text-display--line-height: 3.25rem;
--text-display--font-weight: var(--font-weight-bold);
--text-display--letter-spacing: var(--tracking-tight);
--text-h1: var(--text-4xl);
--text-h1--line-height: var(--text-4xl--line-height);
--text-h1--font-weight: var(--font-weight-bold);
--text-h1--letter-spacing: var(--tracking-tight);
--text-h2: var(--text-3xl);
--text-h2--line-height: var(--text-3xl--line-height);
--text-h2--font-weight: var(--font-weight-semibold);
--text-h2--letter-spacing: var(--tracking-tight);
--text-h3: var(--text-2xl);
--text-h3--line-height: var(--text-2xl--line-height);
--text-h3--font-weight: var(--font-weight-semibold);
--text-h4: var(--text-xl);
--text-h4--line-height: var(--text-xl--line-height);
--text-h4--font-weight: var(--font-weight-semibold);
--text-h5: var(--text-lg);
--text-h5--line-height: var(--text-lg--line-height);
--text-h5--font-weight: var(--font-weight-semibold);
--text-h6: var(--text-base);
--text-h6--line-height: var(--text-base--line-height);
--text-h6--font-weight: var(--font-weight-semibold);
--text-body-lg: var(--text-lg);
--text-body-lg--line-height: var(--text-lg--line-height);
--text-body: var(--text-base);
--text-body--line-height: var(--text-base--line-height);
--text-body-sm: var(--text-sm);
--text-body-sm--line-height: var(--text-sm--line-height);
--text-label: var(--text-sm);
--text-label--line-height: var(--text-sm--line-height);
--text-label--font-weight: var(--font-weight-medium);
--text-label-sm: var(--text-xs);
--text-label-sm--line-height: var(--text-xs--line-height);
--text-label-sm--font-weight: var(--font-weight-medium);
--text-caption: var(--text-xs);
--text-caption--line-height: var(--text-xs--line-height);
--text-overline: var(--text-xs);
--text-overline--line-height: var(--text-xs--line-height);
--text-overline--font-weight: var(--font-weight-semibold);
--text-overline--letter-spacing: 0.06em;
--text-overline-mono: var(--text-xs);
--text-overline-mono--line-height: var(--text-xs--line-height);
--text-overline-mono--font-weight: var(--font-weight-normal);
--text-overline-mono--letter-spacing: 0.06em;
--text-code: var(--text-sm);
--text-code--line-height: var(--text-sm--line-height);
--font-sans: var(--font-inter);
--font-mono: var(--font-paper-mono);
}
@utility text-overline-mono {
font-family: var(--font-mono);
text-transform: uppercase;
}
@layer base {
* {
@apply border-border outline-ring;
}
body {
@apply bg-background text-foreground font-sans;
}
}
```
---
# Accessibility
How YolkUI components work with a keyboard, screen readers, WCAG AA contrast, right to left and Windows High Contrast, how I test them, and the known gaps.
## What you get
YolkUI builds on [Base UI](https://base-ui.com/react/overview/accessibility), which handles the parts that are hardest to get right: ARIA roles and states, keyboard support from the [WAI-ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/), and focus that moves where it should. On top of that, every component goes through the checks on this page before it goes up. Nothing here is a certification, and I list the gaps I know about near the end.
## Keyboard and screen readers
Every component works with a keyboard alone and tells a screen reader what it is, what state it's in and what it's called. A test runs each example on these pages through the WAI-ARIA pattern of every widget it holds: the roles, the Tab stops and the arrow keys. In development, a component warns in the console when nothing gives it a name.
## Focus
Focus shows as a 2px outline in `--ring`, 2px away from the control, and it appears at once rather than fading in. It's an outline, not a box shadow, because Windows High Contrast mode removes shadows and the focus would vanish with them.
## Contrast
Every text color passes WCAG AA, 4.5:1 on its fill, in light and in dark. Focus outlines, chart colors and other marks that must stand out from the page pass 3:1. A test reads the theme and checks every pair whenever a value changes, and [Theming](https://yolkui.com/docs/theming#colors) shows each number.
## Disabled controls
A disabled button, checkbox, tab or menu item stays in the Tab order with `aria-disabled`, so a keyboard user can still reach it and a tooltip can say why it's off. It fades to 60% and still responds to hover, so the tooltip opens. Input, Native Select, Combobox and Slider use the browser's own disabled state instead, which Tab skips, so their pages put the reason in a FieldDescription, where everyone can read it.
## Color is never the only signal
Each status has words or an icon as well as a color. An invalid field shows its error message, an Alert and a Toast draw an icon for their type, and a Badge says what it means in its label.
## Windows High Contrast
In forced colors mode the system replaces every color. Components draw a border wherever their edge was a fill or a shadow, mark the selected item in the system's highlight color, and use the system's gray for disabled controls in place of the fade.
## Right to left
Components use logical properties (start and end, never left and right), so they mirror themselves for Arabic, Hebrew and Persian. Arrow keys and popups follow Base UI's DirectionProvider, so wrap your app in it beside `dir="rtl"`.
```tsx
import { DirectionProvider } from "@base-ui/react/direction-provider"
export default function App({ children }) {
return (
{children}
)
}
```
## Reduced motion
When the system asks for reduced motion, popups fade without the zoom, the selection in Tabs and Segmented Control moves without sliding, and a loading spinner turns more slowly.
## Phones and touch
Text in a field is 16px on small screens, so iOS Safari doesn't zoom in when you tap it. Hover colors only apply on devices that can hover, so a tap never leaves a control lit.
## How I test
Every component runs through these before it goes up, and again on every change:
- **axe** on every component.
- **WAI-ARIA patterns** for every example: roles, names, Tab stops and arrow keys.
- **Right to left:** every horizontal widget pressed in both directions, ArrowLeft in RTL against ArrowRight in LTR.
- **Contrast** of every color pair in both themes, read from the theme file.
- **Server rendering:** every example rendered on a server and hydrated in a browser with another locale and time zone, with no mismatch.
- **Browsers:** Playwright in Chromium, Firefox, WebKit and an iPhone profile for the first components, Windows High Contrast emulated in Chromium.
- **VoiceOver with Safari,** by hand, for several components so far.
## Known gaps
Where YolkUI falls short today:
- The soft ring around a field and the selected state in Tabs, Toggle and Pagination are about 1.2:1 against the page, under the 3:1 that WCAG 1.4.11 asks for. shadcn/ui makes the same trade. A project that needs strict compliance can raise `--input` and the selected fills in its theme.
- I haven't checked NVDA or JAWS on Windows yet, and VoiceOver hasn't covered every component.
- The newer components don't have browser tests yet. A full pass across browsers and real devices comes before version 1.0.
## Your part
A component can only be as accessible as the content you give it:
- Give every field a label, with [Field](https://yolkui.com/docs/components/field) or [Label](https://yolkui.com/docs/components/label).
- Give an icon-only button an `aria-label`.
- Write alt text for images that carry meaning, and `alt=""` for decoration.
- If you change a color token, check its text still reaches 4.5:1 in both themes.
- Keep the focus outline. If you restyle it, keep it visible and keep it an outline.
- When a control is disabled, say why, in a tooltip or a description.
---
# CLI
The YolkUI CLI sets up your project and copies components into it. Three commands, init, add and list, plus options for CI, AI agents and other registries.
## init
Sets up YolkUI in your project. It checks for React, Tailwind CSS v4, a CSS file that imports Tailwind and an import alias such as `@/`, and stops with a message if one is missing. Then it writes `components.json`, adds the theme tokens to your CSS and adds `cn()` to `lib/utils.ts`. If `components.json` is already there, `init` uses its paths.
```bash
npx @yolkui/cli init
```
## add
Copies one or more components into your project, together with the components they use, and installs their npm packages with the package manager your lockfile names. It never replaces a file you already have unless you say yes. If your CSS sets some tokens to other values, `add` asks once whether to use the YolkUI values. It leaves the rest of the file as it is. In a project without `components.json`, `add` offers to run `init` first.
```bash
npx @yolkui/cli add button input tooltip
```
## list
Shows every component with one line about it.
```bash
npx @yolkui/cli list
```
## Options
Every command takes these.
| Option | What it does |
| --- | --- |
| -y, --yes | Takes the default answer to every question: keeps the files you already have and uses the YolkUI token values. |
| -o, --overwrite | Replaces files that already exist and differ. |
| --no-install | Prints the install command instead of running it. |
| --cwd | Runs in another folder. The default is the current one. |
| --registry | Reads another registry, such as a local copy. The default is `https://yolkui.com/r`. |
| -h, --help | Shows the commands and options. |
| -v, --version | Shows the version. |
## In CI and with AI agents
Without a terminal to ask in, the CLI takes the default answer to each question, the same as `--yes`: it keeps the component files you already have and uses the YolkUI token values in your CSS. It prints each file it created, kept or updated, so a script or an AI agent can see what changed.
```bash
npx @yolkui/cli add dialog --yes
```
## components.json
The CLI reads its paths from `components.json`, the file other registry CLIs read too, so a project keeps one set. Change the aliases there to put components somewhere else, and the CLI rewrites their imports to match.
```tsx
{
"tailwind": { "css": "app/globals.css" },
"aliases": {
"components": "@/components",
"ui": "@/components/ui",
"utils": "@/lib/utils",
"lib": "@/lib"
}
}
```
## Registry
Every component is also a JSON file in the public registry item format, at `yolkui.com/r/.json`, so any client that reads that format can install it, the shadcn CLI included.
```bash
npx shadcn add https://yolkui.com/r/button.json
```
## When something goes wrong
The CLI stops before it writes anything and says what is missing. The usual causes:
- **No package.json:** run the command in your project's folder, or pass `--cwd`.
- **No Tailwind CSS, or Tailwind CSS v3:** YolkUI needs Tailwind CSS v4. Its [upgrade guide](https://tailwindcss.com/docs/upgrade-guide) moves a v3 project across.
- **No CSS file imports Tailwind:** add `@import "tailwindcss"` to your main CSS file and run `init` again.
- **No import alias found:** add `"paths": { "@/*": ["./*"] }` to `tsconfig.json` (or `./src/*` in a Vite project) and run `init` again.
- **Installing failed:** the CLI prints the install command, so you can run it yourself.
---
# All components
Every YolkUI component on one page: buttons, form controls, menus, dialogs, navigation and feedback, each built on Base UI and styled with Tailwind CSS v4.
- [Accordion](https://yolkui.com/docs/components/accordion): Headings that each open the section under them: questions and answers, settings, filters.
- [Alert](https://yolkui.com/docs/components/alert): A message in the page, where it applies: a notice, a success, a warning or an error, with buttons and a close.
- [Alert Dialog](https://yolkui.com/docs/components/alert-dialog): Asks before something that cannot be undone; a click outside never closes it.
- [Avatar](https://yolkui.com/docs/components/avatar): A photo with initials as the fallback, a status badge and overlapping groups.
- [Badge](https://yolkui.com/docs/components/badge): A status or category label in solid, subtle, outline or dot emphasis.
- [Breadcrumb](https://yolkui.com/docs/components/breadcrumb): The path from the top of a site to the current page, each step a link back.
- [Button](https://yolkui.com/docs/components/button): A button or a link styled as one, with sizes, variants, icons and a loading state that keeps its width.
- [Button Group](https://yolkui.com/docs/components/button-group): Joins buttons and fields into one control, with separators that match each button.
- [Calendar](https://yolkui.com/docs/components/calendar): A month of days to pick a date or a range, with days that cannot be picked.
- [Card](https://yolkui.com/docs/components/card): A container with header, content and footer that share one edge.
- [Checkbox](https://yolkui.com/docs/components/checkbox): An on/off choice, mixed for a parent over a group.
- [Combobox](https://yolkui.com/docs/components/combobox): A field you type into to filter a list, with chips for several values.
- [Context Menu](https://yolkui.com/docs/components/context-menu): A menu of actions on whatever was right-clicked or long-pressed.
- [Dialog](https://yolkui.com/docs/components/dialog): A window over the page that holds focus until it closes: a form, a confirmation, details.
- [Dropdown Menu](https://yolkui.com/docs/components/dropdown-menu): A menu of actions opened from a button: icons, shortcuts, check and radio items, submenus.
- [Field](https://yolkui.com/docs/components/field): Label, description and error message wired to a field, and a fieldset with its legend.
- [Input](https://yolkui.com/docs/components/input): Text, password, search and file fields in four sizes.
- [Input Group](https://yolkui.com/docs/components/input-group): The field surface: an input with text, icons or buttons at either end.
- [Label](https://yolkui.com/docs/components/label): A plain label for a control outside a Field.
- [Native Select](https://yolkui.com/docs/components/native-select): The browser's own select, styled: the system's list on every device.
- [Navigation Menu](https://yolkui.com/docs/components/navigation-menu): The row of links at the top of a site; some items open a panel of more links.
- [Pagination](https://yolkui.com/docs/components/pagination): Links to the pages of a long list: Previous, the page numbers, Next.
- [Popover](https://yolkui.com/docs/components/popover): A small panel opened from a button: a short form, settings or a date picker, with the page usable around it.
- [Progress](https://yolkui.com/docs/components/progress): How much of a task is done, as a bar with a label and a value; a sliding piece when nobody knows how long.
- [Radio Group](https://yolkui.com/docs/components/radio-group): One choice from a short list, named by a legend.
- [Segmented Control](https://yolkui.com/docs/components/segmented-control): Picks one value from a few and is never empty; the selection slides between equal-width items.
- [Select](https://yolkui.com/docs/components/select): Picks one value from a list that opens over the trigger, the chosen item in place.
- [Slider](https://yolkui.com/docs/components/slider): A value picked by dragging along a line: one thumb for a number, two for a range.
- [Switch](https://yolkui.com/docs/components/switch): A setting that turns on or off and takes effect at once.
- [Tabs](https://yolkui.com/docs/components/tabs): Switches the panel below it; each tab hugs its label and the selection slides between them.
- [Textarea](https://yolkui.com/docs/components/textarea): A multi-line field that grows with its content.
- [Toast](https://yolkui.com/docs/components/toast): A short message at the edge of the screen that leaves by itself: saved, sent, failed, undo.
- [Toggle](https://yolkui.com/docs/components/toggle): A button that stays pressed: bold in a toolbar, a pinned item, a filter.
- [Toggle Group](https://yolkui.com/docs/components/toggle-group): Toggles that work as one: one tab stop, arrow keys between items, one or several on.
- [Toolbar](https://yolkui.com/docs/components/toolbar): Buttons, toggles and toggle groups in one row: one tab stop, arrow keys across them all.
- [Tooltip](https://yolkui.com/docs/components/tooltip): A short description of a control, on hover and on keyboard focus.
---
# Accordion
Headings that each open the section under them: questions and answers, settings, filters.
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
/** Questions and answers: one section open at a time, the first open to start with. */
export default function AccordionDemo() {
return (
How long does shipping take?
Orders leave our warehouse the next working day and arrive in three to five working days.
What is your return policy?
Send anything back within 30 days of delivery, unused and in its box, for a full refund.
How do I reach support?
Write to us from the Help page in your account. We answer within one working day.
)
}
```
## Installation
```bash
npx @yolkui/cli add accordion
```
Manual: install @base-ui/react@^1.8.0, then copy components/ui/accordion.tsx.
## Usage
For several sections a reader opens one at a time: questions and answers, settings, filters. For views of the same content side by side, use Tabs; for a small panel over the page, a Popover.
Each AccordionItem holds an AccordionTrigger, the heading, and an AccordionContent, its section. One section is open at a time; defaultValue (an array of item values) opens some to start with, and value with onValueChange controls them from the page. A line separates the sections and there is no box, so it sits in a page, a card or a popover as text does.
- The heading is a real heading (h3 by default). Set headingLevel on AccordionTrigger to fit the page's outline, as headingLevel={4} inside a Card with an h3 title.
- Links in a section are underlined; paragraphs are 16 apart.
- For a single section that shows and hides on its own, a button and a panel are enough; for views of the same content side by side, use Tabs.
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
How long does shipping take?Three to five working days.
```
## Composition
```text
Accordion
└── AccordionItem
├── AccordionTrigger
└── AccordionContent
```
## Examples
### Several open at once
With multiple, opening one section leaves the others as they are: settings, filters, anything a person compares.
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
/** With multiple, opening one section leaves the others as they are. */
export default function AccordionMultiple() {
return (
Notifications
Email for mentions and replies, a weekly summary on Mondays.
Push notifications are off on this device.
PrivacyYour profile is visible to members of your workspace only.Signed-in devicesMacBook Pro, Safari, last active today. iPhone 15, last active yesterday.
)
}
```
### Disabled
disabled on an AccordionItem keeps its section closed. The heading fades and stays focusable, so wrap it in a Tooltip that says why; disabled on the Accordion turns off every section.
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
/**
* A disabled section fades to 60% and does not open, but its heading keeps focus
* (aria-disabled), so Tab still reaches it and a screen reader says it is dimmed. A
* Tooltip around it says why, on hover and on focus.
*/
export default function AccordionDisabled() {
return (
Plan and billingPro plan, billed yearly. Next invoice on 1 March.}>Single sign-on
Available on the Business planConnect your identity provider with SAML.Export dataDownload every project as a ZIP of JSON files.
)
}
```
### In a box
For a busy page, give the Accordion a border, a radius and some padding: className="rounded-lg border border-border px-4".
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
/** A box around it, for a busy page: a border and radius on the Accordion, padding inside. */
export default function AccordionBorders() {
return (
How does billing work?You are billed at the start of each month for the seats in your workspace.Can I change the number of seats?Yes. Added seats are charged for the rest of the month; removed ones are credited.How do I cancel?From Settings, Billing. Your workspace stays open until the end of the paid month.
)
}
```
### In a Card
In a Card the accordion needs nothing extra: the card's edge is the only box.
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
/** In a Card it has no box of its own, so the card's edge is the only one. */
export default function AccordionCard() {
return (
}>Frequently asked
About your subscription.Is there a free trial?Fourteen days on any plan, no card needed.Can I upgrade later?Any time. You pay the difference for the rest of the billing period.
)
}
```
### Found by the browser's search
hiddenUntilFound keeps closed sections in the page, hidden until found: the browser's find (Ctrl+F or Cmd+F) searches them and opens the one with the match, and search engines read them. Browsers that do not support it keep them closed until opened.
```tsx
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
/**
* hiddenUntilFound keeps closed sections in the page as hidden="until-found": the
* browser's find (Ctrl+F or Cmd+F) searches them and opens the one that matches, and
* search engines index them. Try "restocking".
*/
export default function AccordionFind() {
return (
Can I exchange an item?Yes, for another size or color within 30 days.Are there any fees?Returns are free. Large items carry a restocking fee of 10%.
)
}
```
### Right to left
In a right-to-left page the heading starts on the right and the chevron sits on the left, on their own.
```tsx
import { DirectionProvider } from "@base-ui/react/direction-provider"
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"
/** Right to left: the heading starts on the right and the chevron sits on the left, on their own (logical properties). */
export default function AccordionRtl() {
return (
{/* How long does shipping take? / Three to five working days. */}
كم يستغرق الشحن؟من ثلاثة إلى خمسة أيام عمل.
{/* What is your return policy? / Within 30 days, for a full refund. */}
ما هي سياسة الإرجاع؟خلال 30 يومًا من الاستلام، مع استرداد كامل المبلغ.
)
}
```
## API Reference
Our additions on top of Base UI's Accordion (value, defaultValue, onValueChange, multiple, disabled, hiddenUntilFound, keepMounted and the rest work as in Base UI).
| Prop | On | Values | Default |
| --- | --- | --- | --- |
| headingLevel | `AccordionTrigger` | `2` · `3` · `4` · `5` · `6` | `3` |
| className | `AccordionContent` | goes on the inner box that holds the text and its padding | — |
## Accessibility
Each heading is a button inside a heading, which says whether its section is open; the section is a region named by its heading. Screen readers list the headings with the rest of the page's.
- Every heading is its own Tab stop; Enter and Space open and close it. Arrow keys do not move between headings, as the WAI-ARIA accordion pattern now says.
- A disabled heading stays focusable and is announced as dimmed, so a Tooltip can explain it.
- Each open section is a region, a landmark screen readers list. When many sections can be open at once (multiple, more than about six), give AccordionContent role="group" so the landmark list stays short.
- The section slides open in 150ms, and at once when the system asks for reduced motion.
- Color is never the only sign: the chevron turns with the section, and the screen reader hears expanded or collapsed.
### Keyboard
| Key | What it does |
| --- | --- |
| Tab | Moves to the next heading. |
| Shift + Tab | Moves to the previous heading. |
| Enter · Space | Opens or closes the focused heading's section. |
---
# Alert
A message in the page, where it applies: a notice, a success, a warning or an error, with buttons and a close.
```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
export default function AlertDemo() {
return (
Your trial ends in 3 daysAdd a card to keep your projects and everyone on your team.
)
}
```
## Installation
```bash
npx @yolkui/cli add alert
```
Manual: install @base-ui/react@^1.8.0, then copy components/ui/alert.tsx.
## Usage
A message about this part of the page that stays until it is dealt with: a notice, a success, a warning, an error. For a passing message use a Toast; for a question that must be answered first, an Alert Dialog; for an error on one field, its FieldError.
```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
Your trial ends in 3 daysAdd a payment method to keep your projects.
```
## Composition
```text
Alert
├── AlertTitle
├── AlertDescription
├── AlertAction
└── AlertClose
```
## Examples
### Tones
tone sets the icon and the color of the icon and the text: neutral, info, success, warning or destructive. The alert itself stays a neutral card. Write the title so it says what happened without the color.
```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
/** Each tone has its icon and writes the text in its color; the words still say what happened. */
export default function AlertTones() {
return (
Scheduled maintenanceThe dashboard will be read-only on Sunday from 02:00 to 04:00 UTC.A new version is readyReload the page to get it.Payment receivedA receipt is on its way to your email.Storage almost fullYou have used 9.4 of 10 GB.Payment failedCheck your card details and try again.
)
}
```
### With buttons
AlertAction holds the buttons. One button sits at the end of the text; with layout="stacked" on the Alert they go under it, which suits two buttons. Use an outline Button for the main action and a ghost one for the second, both size sm.
```tsx
"use client"
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
/** One button sits at the end of the text; two go under it with layout="stacked". Outline for the main action, ghost for the second. */
export default function AlertActionExample() {
return (
A new version is readyRestart to update. Your open work is saved first.Payment failedYour card was declined. Update it to keep your plan.
)
}
```
### In a narrow place
When the alert itself is narrower than 384px, the button moves under the text by itself. It follows the alert's width, not the screen's, so an alert in a sidebar stacks on a wide screen too. layout="inline" or layout="stacked" fixes one of the two.
```tsx
import { Alert, AlertAction, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
/**
* The same alert in a narrow column and in a wide one. Under 384px of its own
* width the button moves under the text by itself; it follows the alert, not the
* screen, so a sidebar on a wide screen stacks too.
*/
export default function AlertNarrow() {
return (
A new version is readyRestart to update.
A new version is readyRestart to update.
)
}
```
### Tinted
emphasis="subtle" fills the whole alert with the tone's light color and writes the text in its dark one. Use it for a message that has to be seen at once among cards and fields; the plain alert is the everyday one.
```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
/** emphasis="subtle" tints the whole alert, for a message that has to be seen from afar. */
export default function AlertSubtle() {
return (
Scheduled maintenanceThe dashboard will be read-only on Sunday from 02:00 to 04:00 UTC.A new version is readyReload the page to get it.Payment receivedA receipt is on its way to your email.Storage almost fullYou have used 9.4 of 10 GB.Payment failedCheck your card details and try again.
)
}
```
### Tinted, with buttons
A gray or a black button sits badly on a color. So on a tinted alert use a secondary Button for the main action: inside it the button takes the alert's own color, one step darker, a look it has only here. A ghost Button for the second action darkens the tint under the pointer the same way, and so does the close button.
```tsx
"use client"
import { Alert, AlertAction, AlertClose, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
/**
* On a tinted alert the main action is a secondary Button: there it takes the
* alert's own color, a step darker. The second action stays a ghost Button.
*/
export default function AlertSubtleAction() {
return (
A new version is readyRestart to update. Your open work is saved first.Payment failedYour card was declined. Update it to keep your plan.
)
}
```
### Closing it
AlertClose adds a × that hides the alert. Focus then goes to the next thing after the alert that can take it, so someone using the keyboard stays where they were; finalFocus on the Alert names another place. Left alone the alert stays closed only while it is on the page: a reload or a new page shows it again. To remember the choice, keep the state with open and onOpenChange and store it.
```tsx
"use client"
import * as React from "react"
import { Alert, AlertClose, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
/**
* AlertClose hides the alert and hands focus to what comes after it. Here the
* page keeps the state, so it can bring the alert back.
*/
export default function AlertCloseExample() {
const [open, setOpen] = React.useState(true)
return (
Your changes are saved
)
}
```
### With a list
A list inside AlertDescription gets its bullets and spacing. Count the problems in the title, so the first words already say how much there is to fix.
```tsx
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
/** Several problems at once: a title that counts them and a list. */
export default function AlertList() {
return (
There were 2 problems with your password
It must include at least 1 number
It must include at least 2 uppercase letters
)
}
```
### One line, with a link
A short message needs no title: AlertDescription alone is one line. A link in the text keeps the text's color and is underlined.
```tsx
import { Alert, AlertDescription } from "@/components/ui/alert"
/** A single line needs no title. A link in the text is underlined and keeps the text's color. */
export default function AlertLink() {
return (
Your trial ends in 3 days. Add a card to keep your projects.
)
}
```
### Another icon, or none
icon replaces the tone's icon with yours, at the same 16px, and icon={false} leaves it out. An svg passed as a child of Alert works too. Without the icon the color is the only thing that tells the tone at a glance, so let the title say it.
```tsx
import { Rocket } from "lucide-react"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
/** icon replaces the tone's icon; icon={false} leaves it out. */
export default function AlertIcon() {
return (
}>
Dark mode is hereTurn it on under your profile settings.You are viewing an archived projectNothing here can be changed.
)
}
```
### Right to left
Under dir="rtl" the icon moves to the right and the buttons to the left on their own. Translate toneLabel with the rest of the text.
```tsx
"use client"
import { Alert, AlertAction, AlertClose, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Button } from "@/components/ui/button"
/**
* In a right-to-left page the icon moves to the right and the button and the ×
* to the left on their own. The text is Arabic (lang="ar"), as in a real RTL app.
*/
export default function AlertRtl() {
return (
// "Information" / "A new version is ready" / "Restart to update." / "Restart" / "Close"
إصدار جديد جاهزأعد التشغيل للتحديث.
)
}
```
## API Reference
Every part takes className and the props of its element.
| Prop | Type | What it does |
| --- | --- | --- |
| tone | `neutral` · `info` · `success` · `warning` · `destructive` | On Alert: the icon and the color. `neutral` by default. |
| emphasis | `plain` · `subtle` | On Alert: a neutral card with the icon and the text in the tone's color, or the whole alert tinted. `plain` by default. |
| layout | `auto` · `inline` · `stacked` | On Alert: AlertAction at the end of the text or under it. `auto` by default: at the end, and under it when the alert is narrower than 384px. |
| toneLabel | `string` · `false` | On Alert: the word a screen reader hears first, "Info", "Success", "Warning" or "Error" by tone. A translation, or `false` for none. |
| icon | node · `false` | On Alert: replaces the tone's icon, or leaves it out. |
| open | `boolean` | On Alert: whether it shows, when the page keeps the state. |
| defaultOpen | `boolean` | On Alert: whether it shows at first. `true` by default. |
| onOpenChange | `(open) => void` | On Alert: called when AlertClose is pressed. |
| finalFocus | ref | On Alert: where focus goes when AlertClose closes it. By default the next element after the alert that can take focus, or the one before it. |
| variant | `default` · `destructive` | On Alert: the names other libraries use, mapped to `neutral` and `destructive`. `tone` wins. |
| AlertTitle | `div` | The heading. `render` makes it a heading of the page's level, e.g. `render={}`. |
| AlertDescription | `div` | The text. Takes paragraphs, lists and links. |
| AlertAction | `div` | The buttons. |
| AlertClose | Button | The ×, named "Close"; `aria-label` translates it. |
## Accessibility
An alert that appears while someone is on the page is read aloud without taking focus.
- warning and destructive are role="alert": a screen reader reads them at once, interrupting what it was saying. The other tones are role="status" and wait until it is idle. Pass role to change it; an alert that is already there when the page loads is not announced either way.
- The tone is never the only sign: every tone has its own icon, and a screen reader hears it as a word before the text ("Error: Payment failed"), which toneLabel translates. The icon itself is hidden from screen readers. Write the title so it says what happened in words.
- The close button is named "Close" and takes the usual focus outline. When it is pressed the alert leaves the page and focus moves to the next element after it that can take focus (the one before it when the alert is last), so a keyboard or screen reader user is not sent back to the top of the page. finalFocus picks another place.
- Text keeps at least 4.5:1 in both themes, on the plain alert and on every tint, the buttons included.
- An alert does not leave by itself. For a message that should, use a Toast; for a question that must be answered before going on, an Alert Dialog; for an error on one field, the field's own error text.
### Keyboard
| Key | What it does |
| --- | --- |
| Tab | Moves to the alert's buttons and links, in order. |
| Enter · Space | Presses the focused button; on the close button, the alert leaves and focus moves to the next element. |
---
# Alert Dialog
Asks before something that cannot be undone; a click outside never closes it.
```tsx
"use client"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
/** Asks before something that cannot be undone. Focus starts on Cancel. */
export default function AlertDialogDemo() {
return (
}>Delete project
Delete “Yolk website”?
Its pages and files are removed for everyone. This cannot be undone.
CancelDelete project
)
}
```
## Installation
```bash
npx @yolkui/cli add alert-dialog
```
Manual: install @base-ui/react@^1.8.0, then copy components/ui/alert-dialog.tsx.
## Usage
Asks before something that cannot be undone, like deleting a project. It must be answered: a click outside never closes it. For a form, details or settings, use a Dialog.
An Alert Dialog asks a question that must be answered before something that cannot be undone. For anything else, a form, a setting, a long text, use Dialog. It is Dialog's surface without the ×: the choice is a button. AlertDialogCancel goes first and AlertDialogAction last; the action names what happens ("Delete project", not "OK") and takes variant="destructive" when it destroys something. Both close the alert (the action after its work, when its onClick is async); a click on the backdrop does not, Escape does, as Cancel.
- Ask only when it matters: an alert for every small action teaches people to click through without reading.
```tsx
import {
AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription,
AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
}>Delete project
Delete this project?Its pages and files are removed for everyone.CancelDelete
```
### Icon
AlertDialogMedia, first in the header, holds an icon in a 40px square, with a 16px glyph as every icon here. It looks best centered, above the title; at the start it sits beside the title and description. tone paints it as the subtle Badge of that tone; match the action, tone="destructive" for a delete. It is hidden from screen readers, so the title must say everything.
## Composition
```text
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
├── AlertDialogHeader
│ ├── AlertDialogMedia
│ ├── AlertDialogTitle
│ └── AlertDialogDescription
└── AlertDialogFooter
├── AlertDialogCancel
└── AlertDialogAction
```
## Examples
### Layout
layout decides the text and the buttons, and nothing else. "start", the default above, puts the text at the start and the buttons at the end, stacked on a phone with the action on top, as Dialog: for a question with more to read. "center" centers the text in balanced lines and gives the buttons equal shares of the row at every width, as macOS and iOS alerts: for a short, clear question, usually with an icon.
```tsx
"use client"
import { Trash2 } from "lucide-react"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogMedia,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
/** layout="center" with an icon above the title in the action's tone, as macOS alerts. */
export default function AlertDialogMediaExample() {
return (
}>Delete chat
Delete this chat?
Its messages and files are removed for everyone in it. This cannot be undone.
CancelDelete chat
)
}
```
### Size
size decides the width, and nothing else: 448px at the start, 384px centered, 320px at "sm". As shadcn's sm, size="sm" centers unless you pass a layout. For a short yes or no.
```tsx
"use client"
import { Bell } from "lucide-react"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogMedia,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
/** size="sm": 320 wide. Without a layout it centers (shadcn's sm); for a short yes or no. */
export default function AlertDialogSmall() {
return (
}>Notifications
Turn on notifications?We let you know when someone mentions you.Not nowTurn on
)
}
```
### From a menu
"Delete…" in a Dropdown Menu or Context Menu opens the alert: control open and set it in the item's onClick. The menu closes first, and when the alert closes focus goes back to the menu's button. End the item's label with an ellipsis: it asks before it acts.
```tsx
"use client"
import * as React from "react"
import { Copy, Ellipsis, Pencil, Trash2 } from "lucide-react"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
/** "Delete…" in a menu opens the alert; the menu closes first, and focus returns to its button. */
export default function AlertDialogFromMenu() {
const [open, setOpen] = React.useState(false)
return (
<>
}>
Rename
Duplicate
setOpen(true)}>
Delete…
Delete “Yolk website”?
Its pages and files are removed for everyone. This cannot be undone.
CancelDelete project
>
)
}
```
### Work that takes time
When the action waits for a server, give AlertDialogAction an async onClick (or return the promise). The alert stays open while it runs: the action shows its loading state, Escape is off, and it closes when the work is done, so a delete is never left running with nothing on screen to say so. If the promise rejects or resolves to false the alert stays open, ready to show the error and try again (show it in the alert with role="alert", so a screen reader hears it). Cancel still works while it loads, so a request that never answers locks no one in; abort the request in onOpenChange if it should stop. loadingText ("Working" by default) is announced to screen readers.
- When your code tracks the work itself and has no promise to return (mutate() and isPending in a data library, a transition), pass loading={isPending}. The action then loads while it is true and never closes the alert by itself; close it from your code when the work succeeds (setOpen(false) in onSuccess).
- Code pasted from shadcn's Base UI alert, where the action never closes, works when its onClick is async and closes the alert itself.
```tsx
"use client"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"
/**
* Work that takes time: an async onClick is all it needs. The alert stays open with
* the action loading, Cancel and Escape off, and closes when the work is done.
* Return false (or let it throw) to keep it open and show an error.
*/
export default function AlertDialogAsync() {
async function remove() {
await new Promise((resolve) => setTimeout(resolve, 1500)) // your request here
}
return (
}>Remove member
Remove Ada Lovelace?Ada loses access to every project in this workspace.Cancel
Remove member
)
}
```
## API Reference
Our props on top of Base UI's AlertDialog (open, defaultOpen, onOpenChange, actionsRef, handle and the rest work as in Base UI). A click outside never closes an alert.
| Prop | On | Values | Default |
| --- | --- | --- | --- |
| layout | `AlertDialogContent` | `"start"` · `"center"` | `"start"`, `"center"` at size="sm" |
| size | `AlertDialogContent` | `"default"` · `"sm"` | `"default"` (448, centered 384; sm 320) |
| tone | `AlertDialogMedia` | neutral · brand · accent · success · info · warning · destructive | `"neutral"` |
| variant | `AlertDialogAction` | Button's variants | `"default"` |
| onClick | `AlertDialogAction` | a function; when it returns a promise the alert waits for it, and stays open on a rejection or `false` | — |
| loading | `AlertDialogAction` | `true` · `false`: your own work state; the action loads and your code closes the alert | — |
| loadingText | `AlertDialogAction` | text announced when the work starts | `"Working"` |
| variant | `AlertDialogCancel` | Button's variants | `"outline"` |
| createAlertDialogHandle() | — | links triggers anywhere to one alert, with a payload | — |
## Accessibility
The popup is an alertdialog, named by its title and described by its description, which screen readers read as it opens. Focus starts on Cancel, wherever it sits in the footer, so Enter on a freshly opened alert never deletes anything; Tab stays inside, and focus returns to the trigger when it closes.
### Keyboard
| Key | What it does |
| --- | --- |
| Tab · Shift + Tab | Moves between the buttons; focus stays inside the dialog. |
| Enter · Space | Presses the focused button. Focus starts on Cancel. |
| Escape | Cancels and closes, unless an action is running. |
---
# Avatar
A photo with initials as the fallback, a status badge and overlapping groups.
```tsx
import { Avatar, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarImage } from "@/components/ui/avatar"
/** Name the group; the count says how many more, in words for a screen reader. */
export default function AvatarGroupExample() {
return (
{(["sm", "default", "lg"] as const).map((size) => (
+3
))}
)
}
```
## Installation
```bash
npx @yolkui/cli add avatar
```
Manual: install @base-ui/react@^1.8.0, then copy components/ui/avatar.tsx.
## Usage
A person or a team in a small picture: their photo when it loads, their initials when it doesn't, and a status dot. Beside a printed name it only helps the eye find it.
```tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
```
## Composition
```text
Avatar
├── AvatarImage
├── AvatarFallback
└── AvatarBadge
AvatarGroup
├── Avatar …
└── AvatarGroupCount
```
## Examples
### Sizes and shape
Five sizes, 24 · 32 · 40 · 48 · 64, and shape="square". name gives the initials and the accessible name.
```tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
const sizes = [
{ size: "sm", label: "sm · 24" },
{ size: "default", label: "default · 32" },
{ size: "lg", label: "lg · 40" },
{ size: "xl", label: "xl · 48" },
{ size: "2xl", label: "2xl · 64" },
] as const
/** A photo, initials from the name, a blank fallback, and the square shape. */
export default function AvatarSizes() {
return (
{sizes.map(({ size, label }) => (
{label}
))}
)
}
```
### Fallback
A photo that fails to load ends in initials, from the name or your own text.
```tsx
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
/** A broken photo ends in initials, from the name or your own text. */
export default function AvatarFallbackExample() {
return (
CN
)
}
```
### Status
AvatarBadge's label is read with the name, "Ada Lovelace (Online)", so the color is never the only signal.
```tsx
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
/** The status words are read with the name: "Ada Lovelace (Online)". */
export default function AvatarStatus() {
return (
)
}
```
### Notification
position="top" puts the dot at the top corner, for unread activity.
```tsx
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
/** position="top" puts the dot at the top corner, for unread activity. */
export default function AvatarNotification() {
return (
{(["sm", "default", "lg", "xl", "2xl"] as const).map((size) => (
))}
)
}
```
### A real photo
A notification at the top and presence at the bottom, on a photo.
```tsx
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
/** A real photo, with a notification at the top and presence at the bottom. */
export default function AvatarPhoto() {
return (
{(["sm", "default", "lg", "xl", "2xl"] as const).map((size) => (
))}
{(["sm", "default", "lg", "xl", "2xl"] as const).map((size) => (
))}
)
}
```
### In a list
When the name is printed beside it, hide the avatar from assistive technology (aria-hidden). On a card-colored surface set --avatar-cutout.
```tsx
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
const members = [
{ name: "Ada Lovelace", email: "ada@yolkui.com", role: "Owner", photo: "/avatars/ada.svg", status: { tone: "success", label: "Online" } },
{ name: "Grace Hopper", email: "grace@yolkui.com", role: "Editor", status: { tone: "warning", label: "Away" } },
{ name: "Margaret Hamilton", email: "margaret@yolkui.com", role: "Viewer", photo: "/avatars/margaret.svg" },
] as const satisfies {
name: string
email: string
role: string
photo?: string
status?: { tone: "success" | "warning"; label: string }
}[]
/**
* The name is printed beside it, so the avatar is hidden from assistive technology.
* On a card-colored surface the cutout ring takes that color (--avatar-cutout).
*/
export default function AvatarList() {
return (
{members.map((member) => (
{"photo" in member ? : null}
{"status" in member ? : null}
{member.name}
{member.email}
{"status" in member ? ` · ${member.status.label.toLowerCase()}` : ""}
{member.role}
))}
)
}
```
## API Reference
Our additions on top of Base UI's Avatar.
| Prop | On | Values | Default |
| --- | --- | --- | --- |
| size | `Avatar` | `sm` · `default` · `lg` · `xl` · `2xl` (24 · 32 · 40 · 48 · 64) | `default` |
| shape | `Avatar` | `circle` (people) · `square` (teams, apps) | `circle` |
| name | `Avatar` | the person's name: the initials and the photo's alt text | — |
| tone | `AvatarBadge` | `success` · `warning` · `destructive` · `neutral` | — |
| label | `AvatarBadge` | the status in words, read with the name ("Online") | — |
| position | `AvatarBadge` | `bottom` (presence) · `top` (a notification) | `bottom` |
| label | `AvatarGroupCount` | the count in words ("3 more people") | — |
## Accessibility
The photo's alt text is the name, and the initials stand in for it until the photo loads.
- Beside a printed name, pass alt="" on AvatarImage so the name is not read twice.
- A status is never only a color: AvatarBadge's label is read with the name ("Ada Lovelace, Online").
- AvatarGroupCount says the number in words, not just "+3".
---
# Badge
A status or category label in solid, subtle, outline or dot emphasis.
```tsx
import { ArrowUpRight, Check, CircleAlert, RefreshCw } from "lucide-react"
import { Badge } from "@/components/ui/badge"
/** Icons are 12px beside the label; a long label ends in an ellipsis. */
export default function BadgeIcons() {
return (
Verified
Expiring
Docs
Syncing
Quarterly-report-final-version-3
)
}
```
## Installation
```bash
npx @yolkui/cli add badge
```
Manual: install @base-ui/react@^1.8.0, class-variance-authority@^0.7.1, then copy components/ui/badge.tsx.
## Usage
A short status or category beside something: "Beta", "Paid", a count. It is text, not a control; for an action use a Button, for a removable value a Combobox chip.
```tsx
import { Badge } from "@/components/ui/badge"
Paid
```
## Examples
### Tones and emphasis
tone picks the color and emphasis how loud it is: solid, subtle, outline or dot. The words carry the meaning, never the color alone.
```tsx
import { Badge } from "@/components/ui/badge"
const tones = [
{ tone: "neutral", label: "Draft" },
{ tone: "brand", label: "Beta" },
{ tone: "accent", label: "New" },
{ tone: "success", label: "Paid" },
{ tone: "info", label: "Syncing" },
{ tone: "warning", label: "Expiring" },
{ tone: "destructive", label: "Failed" },
] as const
const emphases = ["solid", "subtle", "outline", "dot"] as const
/** tone picks the color, emphasis how loud it is. The words carry the meaning. */
export default function BadgeTones() {
return (
{tones.map(({ tone, label }) => (
{tone}
{emphases.map((emphasis) => (
{label}
))}
))}
)
}
```
### Sizes, shape and count
sm and default, shape="pill", and size="count" for a number. A count alone says only a number, so give it context nearby ("3 unread").
```tsx
import { Badge } from "@/components/ui/badge"
/** A count badge alone says only a number: give it context ("3 unread") nearby. */
export default function BadgeSizes() {
return (