Styled kbd
Five keyboard key treatments: a raised 3D key, a flat key, a glow, an outline and a soft key. Each is sized, token-driven and renders a real kbd element.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/kbd-styledDependencies, the @ai2/tokens theme and the component file are installed together.
Copy the source
components/ui/kbd-styled.tsx"use client"
import type * as React from "react"
import { cn } from "@/lib/utils"
/* Kbd family: 5 decorative keys. Colour comes ONLY from tokens (alpha via color-mix or Tailwind opacity). The root is a real <kbd>, data-slot="styled-kbd", font-mono. The effects are pure CSS - framer is not needed; RaisedKbd presses down on :active. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const box: Record<StyledSize, string> = {
sm: "h-5 px-1.5 text-xs",
md: "h-6 px-2 text-xs",
lg: "h-7 px-2.5 text-sm",
xl: "h-8 px-3 text-sm",
}
const base =
"inline-flex w-fit shrink-0 select-none items-center justify-center gap-1 whitespace-nowrap rounded-md font-mono font-medium leading-none [&_svg]:size-3 [&_svg]:shrink-0 [&_i]:text-xs [&_i]:leading-none"
type Props = React.ComponentProps<"kbd"> & { size?: StyledSize }
/* Raised: a 3D physical key - a token bottom-shadow body that presses down on :active. */
export function RaisedKbd({ className, size = "md", children, ...props }: Props) {
return (
<kbd
data-slot="styled-kbd"
className={cn(
base,
box[size],
"border border-border bg-secondary text-secondary-foreground",
"shadow-[0_2px_0_0_color-mix(in_oklab,var(--color-foreground)_18%,transparent)]",
"transition-all duration-(--motion-fast) ease-(--motion-ease)",
"active:translate-y-0.5 active:shadow-[0_0_0_0_color-mix(in_oklab,var(--color-foreground)_18%,transparent)]",
className
)}
{...props}
>
{children}
</kbd>
)
}
/* Flat: temiz duz tus - yuzey token + ince kenar. */
export function FlatKbd({ className, size = "md", children, ...props }: Props) {
return (
<kbd
data-slot="styled-kbd"
className={cn(
base,
box[size],
"border border-border bg-surface-2 text-foreground",
className
)}
{...props}
>
{children}
</kbd>
)
}
/* Glow: yumusak token isima (box-shadow) ile parlayan tus. */
export function GlowKbd({ className, size = "md", children, ...props }: Props) {
return (
<kbd
data-slot="styled-kbd"
className={cn(
base,
box[size],
"border border-info bg-info text-info-foreground",
"shadow-[0_0_12px_-2px_color-mix(in_oklab,var(--color-info)_70%,transparent)]",
className
)}
{...props}
>
{children}
</kbd>
)
}
/* Outline: a transparent body, only a token edge. */
export function OutlineKbd({ className, size = "md", children, ...props }: Props) {
return (
<kbd
data-slot="styled-kbd"
className={cn(
base,
box[size],
"border border-border bg-transparent text-foreground",
className
)}
{...props}
>
{children}
</kbd>
)
}
/* Soft: yumusak-token dolgulu, yuvarlak tus. */
export function SoftKbd({ className, size = "md", children, ...props }: Props) {
return (
<kbd
data-slot="styled-kbd"
className={cn(
base,
box[size],
"border-0 bg-info-soft text-info-soft-foreground",
className
)}
{...props}
>
{children}
</kbd>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Raised
A 3D physical key that presses on active.
import { RaisedKbd } from "@/components/ui/kbd-styled"
<RaisedKbd>Cmd</RaisedKbd>Flat
A clean flat surface-token key.
import { FlatKbd } from "@/components/ui/kbd-styled"
<FlatKbd>Cmd</FlatKbd>Glow
A key with a soft token glow.
import { GlowKbd } from "@/components/ui/kbd-styled"
<GlowKbd>Cmd</GlowKbd>Outline
Transparent body, token border only.
import { OutlineKbd } from "@/components/ui/kbd-styled"
<OutlineKbd>Cmd</OutlineKbd>Soft
A soft-token filled rounded key.
import { SoftKbd } from "@/components/ui/kbd-styled"
<SoftKbd>Cmd</SoftKbd>ai2 Styled kbd: 5 styled variations on the token system
The ai2 Styled kbd are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around keyboard key treatments. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: the raised key presses on active via CSS; no motion library work is required. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, there is no continuous motion to reduce.
What is in the ai2 Styled kbd?
5 exports in one file: Raised, Flat, Glow, Outline and Soft. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: the raised key presses on active via CSS; no motion library work is required.
- Reduced-motion aware: Under prefers-reduced-motion, there is no continuous motion to reduce.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Styled kbd sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.