Skip to Content
CodeUI

Button

@codeui/solid v0.3.0

A labeled action with color variants, sizes, and loading feedback.

When to use

Use Button for an action with a visible label, such as exporting a PNG or copying a snippet. Keep one primary action in each group.

When to choose another component

Use IconButton for a familiar icon action with a tooltip. Use Link for inline navigation.

Live demo

button/basic.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<Button variant="primary" onClick={() => alert("PNG export requested")}>Export PNG</Button>
	);
}

Anatomy

Tap a part to outline it in the demo.

  1. 01Buttonbutton
ExportRendersclasses keydata-cuiRole
Buttonbutton by defaultNonebuttonButton

The leading icon uses an internal span without a data-cui marker. The loading overlay contains three animated dots.

Variants

Colors

button/themes.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="primary">Export PNG</Button>
			<Button variant="secondary">Copy snippet</Button>
			<Button variant="tertiary">Share snippet</Button>
			<Button variant="caution">Overwrite export</Button>
			<Button variant="negative">Delete snippet</Button>
		</div>
	);
}

primary uses brand fill. secondary is neutral. tertiary uses soft brand fill. caution and negative use warning and danger colors. There is no default variant, so specify one.

Sizes

button/sizes.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="secondary" size="xs">Copy snippet (xs)</Button>
			<Button variant="secondary" size="sm">Copy snippet (sm)</Button>
			<Button variant="secondary" size="md">Copy snippet (md)</Button>
			<Button variant="secondary" size="lg">Copy snippet (lg)</Button>
		</div>
	);
}

xs, sm, md, and lg are 28px, 36px, 44px, and 52px at comfortable density. The default is sm. Density adjusts the height without changing the font size.

Ghost

button/ghost.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="primary" ghost>Copy snippet (primary)</Button>
			<Button variant="secondary" ghost>Copy snippet (secondary)</Button>
			<Button variant="tertiary" ghost>Copy snippet (tertiary)</Button>
			<Button variant="caution" ghost>Copy snippet (caution)</Button>
			<Button variant="negative" ghost>Copy snippet (negative)</Button>
		</div>
	);
}

ghost removes the idle fill. The variant colors appear on hover.

Pill

button/pill.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="secondary" pill>Copy snippet</Button>
		</div>
	);
}

pill uses fully rounded corners.

Block

button/block.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ width: "100%" }}><Button variant="secondary" block>Copy snippet</Button></div>
	);
}

block sets width to 100% and flex to 1. Reserve full-width actions for layouts such as stacked phone controls. Desktop dialog and toast actions stay compact.

Leading and trailing icons

button/icons.tsx
import { Button, icons } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="secondary" leftIcon={<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><rect x="8" y="8" width="12" height="12" rx="2" /><path d="M16 8V4H4v12h4" /></svg>}>Copy snippet</Button>
			<Button variant="secondary">Next snippet<icons.NextIcon aria-hidden="true" /></Button>
		</div>
	);
}

leftIcon places an icon before the label. There is no rightIcon prop. Put a trailing icon after the label in children. Set aria-hidden="true" on decorative icons.

button/as-link.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button as="a" href="https://codeimage.dev" variant="secondary">Open CodeImage</Button>
		</div>
	);
}

as="a" accepts href and renders an anchor with button styling. An anchor with href retains native link semantics and uses Enter to follow the destination. Space does not activate an anchor. Use Link for ordinary navigation. A router component passed through as must forward the relevant props and ref.

States

Disabled

button/disabled.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="secondary" disabled>Copy snippet</Button>
		</div>
	);
}

disabled disables a native button and removes it from the tab order. Non-native controls only receive aria-disabled and data-disabled. Kobalte does not add an activation guard or remove href from a button rendered as an anchor. Guard navigation and handlers yourself for that case.

Loading

button/loading.tsx
import { Button } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="secondary" loading>Copy snippet</Button>
		</div>
	);
}

loading places animated dots over the existing content without changing its dimensions. It sets data-loading and blocks pointer events through CSS. It also sets aria-busy="true" and aria-disabled="true", and it ignores clicks, Enter, and Space, so onClick does not run and a submit button does not submit its form. It does not set disabled, so a focused button keeps focus while the action runs.

Ready API

Button

Button renders a styled Kobalte button.

Prop

Type

ButtonProps and buttonStyles are exported from @codeui/solid. buttonStyles.button() returns the base classes. buttonIcon and buttonText are class names. buttonVars exposes the local variable contract.

In CSS-only markup, combine the cui-button class with attributes such as data-size="md", and data-variant="primary". Use data-ghost, data-loading, data-pill, and data-block as presence attributes.

For custom JSX, import buttonStyleProps from @codeui/styles/button. Call buttonStyleProps({ variant: "primary", class: "checkout" }) to get the base and custom classes, the part marker, and the variant attributes. It supplies data-size="sm" by default. The caller manages loading and activation behavior.

Inherited from Kobalte's button contract:

Prop

Type

Accessibility

Keyboard

KeyAction
Tab or Shift+TabMoves focus between enabled controls.
EnterActivates the focused button.
SpaceActivates the focused button.

ARIA

The default native element has button semantics. Kobalte supplies role="button" for non-native elements except anchors with href. It does not add keyboard activation handlers to arbitrary elements. Disabled controls expose data-disabled. The visible text supplies the accessible name. Hide decorative icons from assistive technology. Loading sets aria-busy and aria-disabled, and adds an internal aria-label="Loading" span, so the name reads "Loading" before the label. It does not provide a live region. Supply status feedback outside the button when completion needs an announcement.

Focus

The button styles draw a focus-visible ring with the shared focus tokens. These controls do not open an overlay or move focus on their own. If your handler opens or closes an overlay, that overlay owns focus placement and restoration.

SSR notes

The root and its children render on the server. There is no portal or client-only mount step in Button. Event handlers become active after hydration. Keep the initial props equal on the server and client.

Theming hooks

The shared button styles read these global variables. IconButton uses the same variables.

  • --cui-action-brand-{base,hover,active,text} for primary.
  • --cui-action-neutral-{base,hover,active,text} for secondary and disabled controls.
  • --cui-action-brand-soft-{base,hover,active,text} for tertiary.
  • --cui-action-danger-{base,hover,active,text} for negative.
  • --cui-action-caution-{base,hover,active,text} for caution.
  • --cui-control-height-{xs,sm,md,lg} and --cui-font-size-{xs,sm,md,lg}.
  • --cui-radius-{xs,sm,md,lg,xl,full}, --cui-space-{1,2,4,5,6}, and --cui-font-weight-medium.
  • --cui-border-width, --cui-text-default, and --cui-focus-{width,color,offset}.
  • --cui-motion-duration-{fast,normal} and --cui-motion-ease-out for transitions and the loading overlay.

Each brace expands to a separate variable. See Inkstone color and motion. The local buttonStyles.buttonVars contract controls height, font size, fills, text color, border, padding, and radius.

Current kit sizes, borders, hover rules, and loading motion differ from parts of the Inkstone specification. These galleries document the shipped API.

Composition examples

Open CodeImage
button/composition.tsx
import { Button, Link } from "@codeui/solid";

export default function Demo() {
	return (
		<div style={{ display: "flex", "flex-wrap": "wrap", gap: "var(--cui-space-3)", "align-items": "center" }}>
			<Button variant="primary">Export PNG</Button>
			<Button variant="secondary">Copy snippet</Button>
			<Link href="https://codeimage.dev" variant="underline">Open CodeImage</Link>
		</div>
	);
}

Keep the export action primary, the copy action neutral, and the navigation link inline.

  • Button provides a visible action label.
  • IconButton provides a compact named action.
  • Link provides inline navigation.
  • Tooltip explains an icon action on hover and focus.

On this page