Skip to content
All components
Primitives

Button

Trigger an action, or style a real link as one, with a clear hierarchy between the main action and the rest.

Intent and emphasis as separate axes, in four sizes.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add button

Then import it from @/components/ui/button. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Primary

Official primary filled example. Intent expresses action meaning; emphasis supplies visual weight. Product-specific action hierarchy belongs to the consuming application.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonPrimary() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button>Primary</Button>
      </div>
    </div>
  )
}

Stroke

Official primary stroke example. Choose bordered emphasis while preserving the same native action semantics.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonStroke() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button emphasis="stroke">Stroke</Button>
      </div>
    </div>
  )
}

Lighter

Official primary lighter example. The tinted treatment changes visual weight without introducing a new semantic state.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonLighter() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button emphasis="lighter">Lighter</Button>
      </div>
    </div>
  )
}

Ghost

Official primary ghost example. Inspect the restrained resting appearance and its interaction states in States.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonGhost() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button emphasis="ghost">Ghost</Button>
      </div>
    </div>
  )
}

Neutral

Official neutral intent example. Intent changes styling meaning; native activation and accessible naming responsibilities remain the same.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonNeutral() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button intent="neutral">Neutral</Button>
      </div>
    </div>
  )
}

Error

Official error filled example. Keep action wording explicit; color alone does not explain a destructive operation or provide a confirmation workflow.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonError() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button intent="error">Error</Button>
      </div>
    </div>
  )
}

Error stroke

Official error stroke example. Semantic intent and visual emphasis are independent; this treatment does not introduce a separate variant API.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonErrorStroke() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button intent="error" emphasis="stroke">
          Error stroke
        </Button>
      </div>
    </div>
  )
}

Sizes

Compare xs, sm, md and lg using the complete official size example. Check label length, wrapping of the surrounding layout and usable targets in the consuming context.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonSizes() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button size="xs">xs</Button>
        <Button size="sm">sm</Button>
        <Button size="md">md</Button>
        <Button size="lg">lg</Button>
      </div>
    </div>
  )
}

With icon

Official leading-icon composition. The visible text names the action; icon-only adaptations require a contextual accessible name.

"use client"

import { PlusIcon } from "lucide-react"

import { Button } from "@/components/ui/button"

export function ButtonWithIcon() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button>
          <PlusIcon />
          With icon
        </Button>
      </div>
    </div>
  )
}

Trailing icon

Official trailing-icon composition. Keep the action understandable from its label and preserve content and focus when adapting spacing or size.

"use client"

import { ArrowRightIcon } from "lucide-react"

import { Button } from "@/components/ui/button"

export function ButtonTrailingIcon() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button emphasis="stroke">
          Continue
          <ArrowRightIcon />
        </Button>
      </div>
    </div>
  )
}

Link emphasis

Use the link emphasis for low-priority text actions. emphasis="link" removes fill and padding and underlines on hover, in each intent. It keeps button semantics and the size height for its target.

"use client"

import { Button } from "@/components/ui/button"

export function ButtonLinkEmphasis() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-4">
        <Button emphasis="link">View details</Button>
        <Button intent="neutral" emphasis="link">
          Skip for now
        </Button>
        <Button intent="error" emphasis="link">
          Remove member
        </Button>
        <Button emphasis="link" disabled>
          Unavailable
        </Button>
      </div>
    </div>
  )
}

Anchor actions

Style real anchors as buttons through asChild. Navigation uses one anchor child with href, so link semantics, middle-click and history keep working. Combine asChild with any emphasis, including link.

"use client"

import { ArrowRightIcon, ExternalLinkIcon } from "lucide-react"

import { Button } from "@/components/ui/button"

export function ButtonAnchorActions() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-4">
        <Button asChild intent="neutral" emphasis="stroke">
          <a href="#pricing">
            See pricing
            <ArrowRightIcon />
          </a>
        </Button>
        <Button asChild emphasis="link">
          <a href="#changelog">
            Read the changelog
            <ExternalLinkIcon />
          </a>
        </Button>
      </div>
    </div>
  )
}

Disabled emphases

Compare the disabled treatment across emphases. Native disabled removes the control from activation and the tab order; prefer explaining why an action is unavailable.

"use client"

import { SettingsIcon } from "lucide-react"

import { Button } from "@/components/ui/button"

export function ButtonDisabledEmphases() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button disabled>Filled</Button>
        <Button emphasis="stroke" disabled>
          Stroke
        </Button>
        <Button emphasis="lighter" disabled>
          Lighter
        </Button>
        <Button emphasis="ghost" disabled>
          Ghost
        </Button>
        <Button iconOnly intent="neutral" emphasis="stroke" disabled aria-label="Settings">
          <SettingsIcon />
        </Button>
      </div>
    </div>
  )
}

Loading emphases

Show loading across intents, emphases and an icon-only button. Loading keeps width and focus, exposes aria-busy and aria-disabled, and keeps the accessible name of icon-only buttons.

"use client"

import { Trash2Icon } from "lucide-react"

import { Button } from "@/components/ui/button"

export function ButtonLoadingEmphases() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button loading>Publishing</Button>
        <Button loading intent="neutral" emphasis="stroke">
          Exporting
        </Button>
        <Button loading intent="error" emphasis="lighter">
          Deleting
        </Button>
        <Button loading iconOnly intent="neutral" emphasis="stroke" aria-label="Delete file">
          <Trash2Icon />
        </Button>
      </div>
    </div>
  )
}

Icon only sizes

Compare icon-only buttons at every size. Every icon-only button has an aria-label. The xs size stays at 32px, above the 24px minimum target.

"use client"

import { PlusIcon } from "lucide-react"

import { Button } from "@/components/ui/button"

export function ButtonIconOnlySizes() {
  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Button iconOnly size="xs" intent="neutral" emphasis="stroke" aria-label="Add item, extra small">
          <PlusIcon />
        </Button>
        <Button iconOnly size="sm" intent="neutral" emphasis="stroke" aria-label="Add item, small">
          <PlusIcon />
        </Button>
        <Button iconOnly intent="neutral" emphasis="stroke" aria-label="Add item, medium">
          <PlusIcon />
        </Button>
        <Button iconOnly size="lg" intent="neutral" emphasis="stroke" aria-label="Add item, large">
          <PlusIcon />
        </Button>
        <Button iconOnly aria-label="Create project">
          <PlusIcon />
        </Button>
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Button

Trigger an action with native button semantics, or style a navigation link through asChild and one anchor. Choose intent for meaning and emphasis for visual weight. Give icon-only actions an accessible name. Set type="button" for non-submit actions inside forms; native buttons otherwise default to submit.

Button props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
intent"primary" | "neutral" | "error" | null | undefined"primary"Semantic purpose: primary action, neutral action, or destructive/error action. Independent of visual emphasis. Defaults to primary.
emphasis"link" | "filled" | "stroke" | "lighter" | "ghost" | null | undefined"filled"Visual weight: filled, stroke, lighter, ghost, or link (text only, underlined on hover). Does not change the action's semantics; use asChild with an anchor when it navigates. Defaults to filled.
size"xs" | "sm" | "md" | "lg" | null | undefined"md"Control size: xs, sm, md, or lg. Keep labels and icons readable when choosing a size. Defaults to md.
asChildboolean | undefinedfalseMerge styles and behavior into one child element instead of rendering a button. Use a real anchor with href for navigation; native disabled does not disable an anchor. Defaults to false.
iconOnlyboolean | undefinedfalseSquare button for a single icon at the selected size. Always provide aria-label (or aria-labelledby) because there is no visible text. Defaults to false.
loadingboolean | undefinedfalseShow a spinner while an operation runs. The button keeps its width and focus, exposes aria-busy and aria-disabled, and ignores activation until loading ends; with asChild the spinner renders inside the child and its onClick and navigation are blocked. Defaults to false.
Inherited props (18)
Button inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLButtonElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
namestring | undefined—Name used by the control's form submission or primitive form integration.
type"button" | "submit" | "reset" | undefined—Native button behavior: button, submit or reset. Set button explicitly for non-submit actions inside a form.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLButtonElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLButtonElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLButtonElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLButtonElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLButtonElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/button.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Submit a form, start an operation, or open an overlay such as a dialog, sheet or menu.
  • Navigate with button styling by passing asChild and a single real anchor (or router Link) as the child, so the element stays a link.
  • Show the state of an in-flight action with loading: the button keeps its width and focus and ignores repeated activation.
  • Use iconOnly for a compact, square action in toolbars or table rows, always with an accessible name.

When not to use

  • An on/off setting that applies immediately; that is a state, not an action.
  • A pressed formatting option such as bold or italic, or a set of mutually exclusive views.
  • Plain text navigation inside a paragraph, where a text link reads better and keeps the reading flow.

Anatomy

Button
The element: a native button, or its single child when asChild is set. Carries intent, emphasis (filled, stroke, lighter, ghost or link), size, loading and iconOnly. The link emphasis has no fill or horizontal padding and underlines on hover; it keeps the size height as its target.
Leading or trailing icon
Optional child SVG; sized and spaced by the size variant. Decorative unless it is the only content.
Spinner
Rendered over the content while loading; the label stays in the accessible name.

Keyboard & interaction

  • Enter and Space activate a native button; a link rendered through asChild activates with Enter only, like any link.
  • Focus is shown with a visible outline on keyboard focus only (focus-visible); pointer clicks do not leave a ring.
  • While loading the button stays focusable, sets aria-busy and aria-disabled, and swallows clicks and submissions until loading ends.
  • Disabled buttons are skipped by Tab and ignore pointer input; prefer explaining why an action is unavailable next to it.
  • Hover and pressed feedback come from emphasis, never from color alone; the label never changes on hover.

Responsive behavior

  • Touch targets: keep at least 24x24 CSS pixels (WCAG 2.5.8) and prefer 44x44 for primary actions on touch screens; the md and lg sizes meet the larger target.
  • At narrow widths, stack action rows vertically or let the primary action span the full width; keep the primary action last in reading order on desktop footers and first when stacked.
  • Long labels wrap rather than truncate; never truncate an action label with an ellipsis.
  • Icon-only buttons stay square at every size; do not use them as the only path to an important action on mobile.

Content guidelines

  • Start with a verb that names the outcome: 'Save changes', 'Create project', 'Delete file'.
  • Keep labels to one to three words; put explanations in surrounding text, not in the button.
  • Use sentence case and no trailing punctuation.
  • For destructive actions name the object ('Delete project'), use intent='error', and confirm with an alert dialog when the action cannot be undone.
  • Use the link emphasis for low-priority actions such as Skip or View details; when it navigates, render an anchor with asChild instead of a button.

Alternatives

  • Switch — An immediate on/off setting with a persistent state.
  • Toggle — A pressed state for a single formatting or view option.
  • Toggle group — A set of related pressed options, single or multiple.
  • Dropdown menu — Several secondary actions behind one trigger instead of a row of buttons.

Resources