Button

An interactive button with multiple variants, sizes, icons, loading state, and Motion layout animation.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/button.json

Usage

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

Examples

Default

Variants

Six fills. soft is the accent-tinted secondary that pairs with default, and subtle is its neutral version for toolbars. link paints no fill, so it ignores the size's height and sits on the text line.

Sizes

Four heights (24/28/32/40) plus three square icon sizes. An Input given the same size matches the button beside it in height and corner.

With Icon

Pass an element: it works anywhere, including from a Server Component. A bare component reference (iconStart={Mail}) also works, but only from a Client Component, because a function cannot cross the server/client boundary.

Icon sizes

Pass iconStart or iconEnd and the icon sizes itself (12/14/14/16px across the four heights), with its side padding adjusted to match. Set iconSize only to override it.

With count

Pass count to add a count chip inside the button. It stays readable on every variant and through hover.

A count arriving

Flip the switch: the chip slides in and pops, then fades out faster when it clears, and the button widens and narrows with it instead of jumping. A count already there on load, or one that changes from 3 to 4, stays still. Pass null to clear it; 0 still shows a chip.

Bare and block

variant="bare" is a press target with no fill or label styling, for an avatar, a thumbnail or a run of copy; give it a radius so the focus ring fits. size="block" makes a whole cell or row the target, with no press scale. ghost + block adds the hover tint.

Loading

loading swaps the label for a spinner, blocks the click, and sets aria-busy. The box does not resize, so a row of buttons holds its layout. Each variant keeps its own hover fill while busy, so a loading button reads as the same button mid-press rather than turning into a different one.

API Reference

PropTypeDefaultDescription
variant"default" | "soft" | "ghost" | "destructive" | "subtle" | "link" | "bare""default"Visual style of the button. soft is the accent-tinted secondary that pairs with default; subtle is its neutral equivalent for toolbars. link paints no fill, so it ignores the size's height and padding and sits on the text line at every size. bare is only a focus and press target around its child: no fill, no press scale, no label styling, no height or padding.
size"default" | "xs" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | "inline" | "block""default"Height and padding preset. icon (32px), icon-sm (24px), and icon-lg (40px) are square; inline flows with surrounding text; block is a whole cell or row (full width, height from its content, left-aligned, no press scale). variant="link" and variant="bare" take only the type scale from this, never the height or padding.
iconStartTablerIcon | ReactNodeNoneIcon rendered before the label. Prefer an element (<Mail />); a bare component (Mail) still works but cannot be passed from a Server Component.
iconEndTablerIcon | ReactNodeNoneIcon rendered after the label. Prefer an element (<ChevronRight />); a bare component still works but cannot be passed from a Server Component.
iconSize"xs" | "sm" | "default" | "lg" | "xl"NoneOverrides the icon size implied by size.
countReact.ReactNodeNoneCount chip rendered after the label, tinted to match the variant. Going from null to a value, the chip arrives with a short slide and pop; back to null, it fades out. Its space opens and closes with it, so the button glides to its new width. Changes in between stay still.
countClassNamestringNoneExtra classes for the count chip.
disabledbooleanfalseDims the button to 50% with a not-allowed cursor. It keeps its rest fill, label and size under the pointer: no hover tint, no press. With asChild, the link also gets aria-disabled and leaves the tab order.
loadingbooleanfalseLocks in the variant's hover styling and blocks clicks at once. After about 200ms the label rises out as a centered spinner rises in, and the reverse when it ends; a shorter load shows no spinner. The button's size never changes.
layoutAnimationbooleanfalseMotion layout animation on content changes. Set false to prevent glitches on rapid state changes; disabled automatically under reduced motion.
type"button" | "submit" | "reset""button"Button never submits a form on its own. Pass type="submit" on the one that should.
asChildbooleanfalseRenders the child element instead of a <button>, merging classes and injecting icons, count, and spinner into it.
variant"default" | "soft" | "ghost" | "destructive" | "subtle" | "link" | "bare" = "default"Visual style of the button. soft is the accent-tinted secondary that pairs with default; subtle is its neutral equivalent for toolbars. link paints no fill, so it ignores the size's height and padding and sits on the text line at every size. bare is only a focus and press target around its child: no fill, no press scale, no label styling, no height or padding.
size"default" | "xs" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | "inline" | "block" = "default"Height and padding preset. icon (32px), icon-sm (24px), and icon-lg (40px) are square; inline flows with surrounding text; block is a whole cell or row (full width, height from its content, left-aligned, no press scale). variant="link" and variant="bare" take only the type scale from this, never the height or padding.
iconStartTablerIcon | ReactNodeIcon rendered before the label. Prefer an element (<Mail />); a bare component (Mail) still works but cannot be passed from a Server Component.
iconEndTablerIcon | ReactNodeIcon rendered after the label. Prefer an element (<ChevronRight />); a bare component still works but cannot be passed from a Server Component.
iconSize"xs" | "sm" | "default" | "lg" | "xl"Overrides the icon size implied by size.
countReact.ReactNodeCount chip rendered after the label, tinted to match the variant. Going from null to a value, the chip arrives with a short slide and pop; back to null, it fades out. Its space opens and closes with it, so the button glides to its new width. Changes in between stay still.
countClassNamestringExtra classes for the count chip.
disabledboolean = falseDims the button to 50% with a not-allowed cursor. It keeps its rest fill, label and size under the pointer: no hover tint, no press. With asChild, the link also gets aria-disabled and leaves the tab order.
loadingboolean = falseLocks in the variant's hover styling and blocks clicks at once. After about 200ms the label rises out as a centered spinner rises in, and the reverse when it ends; a shorter load shows no spinner. The button's size never changes.
layoutAnimationboolean = falseMotion layout animation on content changes. Set false to prevent glitches on rapid state changes; disabled automatically under reduced motion.
type"button" | "submit" | "reset" = "button"Button never submits a form on its own. Pass type="submit" on the one that should.
asChildboolean = falseRenders the child element instead of a <button>, merging classes and injecting icons, count, and spinner into it.