Button
Seven variants, four sizes and a loading state that keeps its width.
Variants
5 more takes on the button, each a single file you install on its own by its id.
aui-064Raised
Five tones with a lit top edge. Sinks on press.
$ pnpm dlx asta-ui@latest add button-aui-064aui-065Split
Main action plus a menu behind a chevron.
$ pnpm dlx asta-ui@latest add button-aui-065aui-066Group
Joined buttons for action bars, pagers and views.
$ pnpm dlx asta-ui@latest add button-aui-066aui-067Status
Spinner, then a tick or Retry. Width never jumps.
$ pnpm dlx asta-ui@latest add button-aui-067aui-068Icon toolbar
Icon buttons with tooltips and arrow-key focus.
$ pnpm dlx asta-ui@latest add button-aui-068Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add button --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { Button } from "asta-ui";import { Button } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy this file. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { Slot } from "radix-ui"; import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type ButtonVariant = "solid" | "accent" | "outline" | "soft" | "ghost" | "link" | "danger"; export type ButtonSize = "xs" | "sm" | "md" | "lg"; const BASE = "group/btn relative inline-flex shrink-0 select-none items-center [&_svg]:shrink-0 justify-center whitespace-nowrap font-medium tracking-[-0.01em] outline-none " + "transition-[background-color,color,box-shadow,transform,opacity] duration-200 ease-out active:scale-[0.97] " + "focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper " + "disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none aria-disabled:opacity-45"; // A light top edge and a soft drop give the filled buttons a little body without a gradient. const LIFT = "shadow-[inset_0_1px_0_rgb(255_255_255/0.18),0_1px_2px_rgb(0_0_0/0.16),0_6px_14px_-8px_rgb(0_0_0/0.45)]"; const VARIANT: Record<ButtonVariant, string> = { solid: `bg-ink text-paper ${LIFT} hover:bg-[color-mix(in_srgb,var(--color-ink)_84%,var(--color-paper))]`, accent: `bg-brand text-on-brand ${LIFT} hover:bg-[color-mix(in_srgb,var(--color-brand)_88%,black)]`, danger: `bg-ink text-paper ${LIFT} hover:bg-[color-mix(in_srgb,var(--color-ink)_86%,var(--color-paper))]`, outline: "bg-paper text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent),0_1px_2px_rgb(0_0_0/0.05)] " + "hover:bg-paper-2 hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_24%,transparent),0_1px_2px_rgb(0_0_0/0.05)]", soft: "bg-paper-2 text-ink hover:bg-[color-mix(in_srgb,var(--color-ink)_8%,var(--color-paper-2))]", ghost: "text-ink-2 hover:bg-paper-2 hover:text-ink", // Underline grows from the left on hover. link: "!h-auto !px-0 text-ink bg-[linear-gradient(currentColor,currentColor)] bg-[length:0%_1px] bg-[position:0_100%] bg-no-repeat " + "transition-[background-size,color] duration-300 hover:bg-[length:100%_1px] active:scale-100", }; const SIZE: Record<ButtonSize, string> = { xs: "h-7 gap-1.5 rounded-md px-2.5 text-[12px]", sm: "h-8 gap-1.5 rounded-md px-3 text-[13px]", md: "h-10 gap-2 rounded-lg px-4 text-[14px]", lg: "h-12 gap-2.5 rounded-[9px] px-5 text-[15px]", }; const ICON_ONLY: Record<ButtonSize, string> = { xs: "w-7 !px-0", sm: "w-8 !px-0", md: "w-10 !px-0", lg: "w-12 !px-0" }; interface Own { variant?: ButtonVariant; size?: ButtonSize; /** `pill` rounds fully; `rounded` (default) keeps soft corners. */ shape?: "rounded" | "pill"; /** Shows a spinner over the label and keeps the button's width. */ loading?: boolean; iconLeft?: ReactNode; iconRight?: ReactNode; /** Slide the trailing icon a little on hover. */ nudge?: boolean; /** A square button holding only an icon (give it an `aria-label`). */ iconOnly?: boolean; /** A keyboard hint at the end, e.g. "⌘K". */ kbd?: string; /** * Style the single child element as the button instead of rendering one (Radix Slot), e.g. a router link: * `<Button asChild><Link href="/docs">Docs</Link></Button>`. Icons, `kbd` and `loading` are ignored. */ asChild?: boolean; className?: string; children?: ReactNode; } export type ButtonProps = Own & ((Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof Own> & { href?: undefined }) | (Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof Own> & { href: string })); export function buttonClass({ variant = "solid", size = "md", shape = "rounded", iconOnly = false }: Pick<Own, "variant" | "size" | "shape" | "iconOnly"> = {}) { return cx(BASE, SIZE[size], VARIANT[variant], iconOnly && ICON_ONLY[size], shape === "pill" && "!rounded-full"); } export function Spinner({ className = "" }: { className?: string }) { return ( <svg viewBox="0 0 16 16" className={cx("h-4 w-4 animate-spin", className)} fill="none" aria-hidden> <circle cx="8" cy="8" r="6" stroke="currentColor" strokeOpacity="0.25" strokeWidth="2" /> <path d="M14 8a6 6 0 0 0-6-6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" /> </svg> ); } /** Renders an `<a>` when `href` is given, the child element with `asChild`, otherwise a `<button type="button">`. */ export function Button(props: ButtonProps) { const { variant = "solid", size = "md", shape, loading, iconLeft, iconRight, nudge, iconOnly, kbd, asChild, className, children, ...rest } = props; if (asChild) { return ( <Slot.Root {...(rest as ButtonHTMLAttributes<HTMLElement>)} className={cx(buttonClass({ variant, size, shape, iconOnly }), className)}> {children} </Slot.Root> ); } const filled = variant === "solid" || variant === "accent" || variant === "danger"; const content = ( <> <span className={cx("inline-flex items-center gap-[inherit] transition-opacity duration-200 [&>svg]:h-[1.15em] [&>svg]:w-[1.15em]", loading && "opacity-0")}> {iconLeft && <span className="-ml-0.5 inline-flex shrink-0 [&_svg]:h-[1.1em] [&_svg]:w-[1.1em]">{iconLeft}</span>} {children} {iconRight && ( <span className={cx( "-mr-0.5 inline-flex shrink-0 [&_svg]:h-[1.1em] [&_svg]:w-[1.1em]", nudge && "transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)] group-hover/btn:translate-x-0.5", )} > {iconRight} </span> )} {kbd && ( <kbd className={cx( "-mr-1.5 ml-1 rounded-md px-1.5 font-sans text-[0.8em] leading-[1.6]", filled ? "bg-white/15 text-current" : "bg-[color-mix(in_srgb,var(--color-ink)_7%,transparent)] text-mute", )} > {kbd} </kbd> )} </span> {loading && ( <span className="absolute inset-0 flex items-center justify-center"> <Spinner /> </span> )} </> ); const cls = cx(buttonClass({ variant, size, shape, iconOnly }), className); if (rest.href !== undefined) { const a = rest as AnchorHTMLAttributes<HTMLAnchorElement>; return ( <a {...a} className={cls} aria-disabled={loading || undefined} aria-busy={loading || undefined}> {content} </a> ); } const b = rest as ButtonHTMLAttributes<HTMLButtonElement>; return ( <button type="button" {...b} className={cls} disabled={b.disabled || loading} aria-busy={loading || undefined}> {content} </button> ); } export default Button;"use client"; import { useRender } from "@base-ui/react/use-render"; import { isValidElement, type AnchorHTMLAttributes, type ButtonHTMLAttributes, type ReactElement, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type ButtonVariant = "solid" | "accent" | "outline" | "soft" | "ghost" | "link" | "danger"; export type ButtonSize = "xs" | "sm" | "md" | "lg"; const BASE = "group/btn relative inline-flex shrink-0 select-none items-center [&_svg]:shrink-0 justify-center whitespace-nowrap font-medium tracking-[-0.01em] outline-none " + "transition-[background-color,color,box-shadow,transform,opacity] duration-200 ease-out active:scale-[0.97] " + "focus-visible:ring-2 focus-visible:ring-brand/50 focus-visible:ring-offset-2 focus-visible:ring-offset-paper " + "disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none aria-disabled:opacity-45"; // A light top edge and a soft drop give the filled buttons a little body without a gradient. const LIFT = "shadow-[inset_0_1px_0_rgb(255_255_255/0.18),0_1px_2px_rgb(0_0_0/0.16),0_6px_14px_-8px_rgb(0_0_0/0.45)]"; const VARIANT: Record<ButtonVariant, string> = { solid: `bg-ink text-paper ${LIFT} hover:bg-[color-mix(in_srgb,var(--color-ink)_84%,var(--color-paper))]`, accent: `bg-brand text-on-brand ${LIFT} hover:bg-[color-mix(in_srgb,var(--color-brand)_88%,black)]`, danger: `bg-ink text-paper ${LIFT} hover:bg-[color-mix(in_srgb,var(--color-ink)_86%,var(--color-paper))]`, outline: "bg-paper text-ink shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent),0_1px_2px_rgb(0_0_0/0.05)] " + "hover:bg-paper-2 hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_24%,transparent),0_1px_2px_rgb(0_0_0/0.05)]", soft: "bg-paper-2 text-ink hover:bg-[color-mix(in_srgb,var(--color-ink)_8%,var(--color-paper-2))]", ghost: "text-ink-2 hover:bg-paper-2 hover:text-ink", // Underline grows from the left on hover. link: "!h-auto !px-0 text-ink bg-[linear-gradient(currentColor,currentColor)] bg-[length:0%_1px] bg-[position:0_100%] bg-no-repeat " + "transition-[background-size,color] duration-300 hover:bg-[length:100%_1px] active:scale-100", }; const SIZE: Record<ButtonSize, string> = { xs: "h-7 gap-1.5 rounded-md px-2.5 text-[12px]", sm: "h-8 gap-1.5 rounded-md px-3 text-[13px]", md: "h-10 gap-2 rounded-lg px-4 text-[14px]", lg: "h-12 gap-2.5 rounded-[9px] px-5 text-[15px]", }; const ICON_ONLY: Record<ButtonSize, string> = { xs: "w-7 !px-0", sm: "w-8 !px-0", md: "w-10 !px-0", lg: "w-12 !px-0" }; interface Own { variant?: ButtonVariant; size?: ButtonSize; /** `pill` rounds fully; `rounded` (default) keeps soft corners. */ shape?: "rounded" | "pill"; /** Shows a spinner over the label and keeps the button's width. */ loading?: boolean; iconLeft?: ReactNode; iconRight?: ReactNode; /** Slide the trailing icon a little on hover. */ nudge?: boolean; /** A square button holding only an icon (give it an `aria-label`). */ iconOnly?: boolean; /** A keyboard hint at the end, e.g. "⌘K". */ kbd?: string; /** * Style the single child element as the button instead of rendering one (Base UI useRender), e.g. a router link: * `<Button asChild><Link href="/docs">Docs</Link></Button>`. Icons, `kbd` and `loading` are ignored. */ asChild?: boolean; className?: string; children?: ReactNode; } export type ButtonProps = Own & ((Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof Own> & { href?: undefined }) | (Omit<AnchorHTMLAttributes<HTMLAnchorElement>, keyof Own> & { href: string })); export function buttonClass({ variant = "solid", size = "md", shape = "rounded", iconOnly = false }: Pick<Own, "variant" | "size" | "shape" | "iconOnly"> = {}) { return cx(BASE, SIZE[size], VARIANT[variant], iconOnly && ICON_ONLY[size], shape === "pill" && "!rounded-full"); } export function Spinner({ className = "" }: { className?: string }) { return ( <svg viewBox="0 0 16 16" className={cx("h-4 w-4 animate-spin", className)} fill="none" aria-hidden> <circle cx="8" cy="8" r="6" stroke="currentColor" strokeOpacity="0.25" strokeWidth="2" /> <path d="M14 8a6 6 0 0 0-6-6" stroke="currentColor" strokeWidth="2" strokeLinecap="round" /> </svg> ); } /** Renders an `<a>` when `href` is given, the child element with `asChild`, otherwise a `<button type="button">`. */ export function Button(props: ButtonProps) { const { variant = "solid", size = "md", shape, loading, iconLeft, iconRight, nudge, iconOnly, kbd, asChild, className, children, ...rest } = props; if (asChild && isValidElement(children)) { return <Slotted element={children as ReactElement} props={{ ...(rest as ButtonHTMLAttributes<HTMLElement>), className: cx(buttonClass({ variant, size, shape, iconOnly }), className) }} />; } const filled = variant === "solid" || variant === "accent" || variant === "danger"; const content = ( <> <span className={cx("inline-flex items-center gap-[inherit] transition-opacity duration-200 [&>svg]:h-[1.15em] [&>svg]:w-[1.15em]", loading && "opacity-0")}> {iconLeft && <span className="-ml-0.5 inline-flex shrink-0 [&_svg]:h-[1.1em] [&_svg]:w-[1.1em]">{iconLeft}</span>} {children} {iconRight && ( <span className={cx( "-mr-0.5 inline-flex shrink-0 [&_svg]:h-[1.1em] [&_svg]:w-[1.1em]", nudge && "transition-transform duration-300 ease-[cubic-bezier(.16,1,.3,1)] group-hover/btn:translate-x-0.5", )} > {iconRight} </span> )} {kbd && ( <kbd className={cx( "-mr-1.5 ml-1 rounded-md px-1.5 font-sans text-[0.8em] leading-[1.6]", filled ? "bg-white/15 text-current" : "bg-[color-mix(in_srgb,var(--color-ink)_7%,transparent)] text-mute", )} > {kbd} </kbd> )} </span> {loading && ( <span className="absolute inset-0 flex items-center justify-center"> <Spinner /> </span> )} </> ); const cls = cx(buttonClass({ variant, size, shape, iconOnly }), className); if (rest.href !== undefined) { const a = rest as AnchorHTMLAttributes<HTMLAnchorElement>; return ( <a {...a} className={cls} aria-disabled={loading || undefined} aria-busy={loading || undefined}> {content} </a> ); } const b = rest as ButtonHTMLAttributes<HTMLButtonElement>; return ( <button type="button" {...b} className={cls} disabled={b.disabled || loading} aria-busy={loading || undefined}> {content} </button> ); } /** Renders the child element with the button's props merged in (classes joined, handlers chained). */ function Slotted({ element, props }: { element: ReactElement; props: ButtonHTMLAttributes<HTMLElement> }) { return useRender({ render: element, props: props as Record<string, unknown> }); } export default Button;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Button component to my project. Seven variants, four sizes and a loading state that keeps its width. It includes: solid, accent, outline, soft, ghost, link, danger, loading, icon. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add button --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/button.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Button } from "@/components/astabyte/button"; ``` Usage example and props: https://ui.astabyte.com/button Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Button component to my project. Seven variants, four sizes and a loading state that keeps its width. It includes: solid, accent, outline, soft, ghost, link, danger, loading, icon. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add button ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/button.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Button } from "@/components/astabyte/button"; ``` Usage example and props: https://ui.astabyte.com/button Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div style="display:flex;flex-wrap:wrap;gap:12px;align-items:center"> <button class="asta-btn"><span class="asta-btn-label">Deploy</span></button> <button class="asta-btn asta-btn-accent"><span class="asta-btn-label">Save</span></button> <button class="asta-btn asta-btn-outline"><span class="asta-btn-label">Search <kbd class="asta-btn-kbd">⌘K</kbd></span></button> <button class="asta-btn asta-btn-ghost asta-btn-sm"><span class="asta-btn-label">Cancel</span></button> <button class="asta-btn asta-btn-danger"><span class="asta-btn-label">Delete</span></button> <button class="asta-btn asta-btn-accent" hx-post="/save"><span class="asta-btn-label">Save with htmx</span><span class="asta-btn-spinner" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none"><circle cx="8" cy="8" r="6" stroke="currentColor" stroke-opacity="0.25" stroke-width="2"/><path d="M14 8a6 6 0 0 0-6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg></span></button> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { Button } from "@/components/astabyte/button";
const Arrow = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d="M4 12h15" />
<path d="m13 6 6 6-6 6" />
</svg>
);
const Plus = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d="M12 5v14" />
<path d="M5 12h14" />
</svg>
);
const Heart = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<path d="M12 19.5s-7.5-4.4-7.5-10A4.2 4.2 0 0 1 12 7a4.2 4.2 0 0 1 7.5 2.5c0 5.6-7.5 10-7.5 10Z" />
</svg>
);
const Row = ({ label, children }: { label: string; children: React.ReactNode }) => (
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
<span className="w-20 shrink-0 font-mono text-[11px] uppercase tracking-wider text-mute">{label}</span>
<div className="flex flex-wrap items-center gap-2.5">{children}</div>
</div>
);
export default function ButtonDemo() {
const [saving, setSaving] = useState(false);
const [liked, setLiked] = useState(false);
const save = () => {
setSaving(true);
setTimeout(() => setSaving(false), 1600);
};
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex flex-col gap-6">
<Row label="Variant">
<Button>Solid</Button>
<Button variant="accent">Accent</Button>
<Button variant="outline">Outline</Button>
<Button variant="soft">Soft</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="danger">Delete</Button>
<Button variant="link">Link</Button>
</Row>
<Row label="Size">
<Button size="xs">Extra small</Button>
<Button size="sm">Small</Button>
<Button size="md">Medium</Button>
<Button size="lg">Large</Button>
</Row>
<Row label="Icons">
<Button variant="accent" iconRight={<Arrow />} nudge>
Get started
</Button>
<Button variant="outline" iconLeft={<Plus />}>
New project
</Button>
<Button variant="soft" kbd="⌘K">
Search
</Button>
<Button variant="outline" iconOnly aria-label="Like" aria-pressed={liked} onClick={() => setLiked((v) => !v)} className={liked ? "text-ink" : ""}>
<Heart />
</Button>
</Row>
<Row label="Shape">
<Button shape="pill" iconRight={<Arrow />} nudge>
Launch app
</Button>
<Button shape="pill" variant="outline">
Read docs
</Button>
<Button shape="pill" variant="soft" size="sm">
Pill small
</Button>
</Row>
<Row label="State">
<Button loading={saving} onClick={save}>
Save changes
</Button>
<Button variant="outline" loading>
Loading
</Button>
<Button variant="accent" disabled>
Disabled
</Button>
</Row>
</div>
</div>
);
}