shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A button runs one action when it's pressed: save a form, open a dialog, delete a row. It renders a real <button> with its type set to button, so it never submits a form you didn't mean it to, and it comes in six variants and five sizes, each size with a square twin for an icon.
For a control that stays on or off, such as bold in an editor, use a Toggle. To join related actions into one bar, put them in a Button Group.
Installation
Anatomy

Usage
<script setup lang="ts">
import { ArrowUpIcon } from "lucide-vue-next";
import { Button } from "@/components/ui/button";
</script>
<template>
<div class="flex items-center gap-2">
<Button variant="outline">Button</Button>
<Button aria-label="Submit" size="icon-md" variant="outline">
<ArrowUpIcon aria-hidden="true" />
</Button>
</div>
</template>
Accessibility
Button renders a native <button>, so the browser gives it the button role and a place in the tab order, and its text becomes its accessible name. An icon-only button has no text, so give it an aria-label, as in the Icon demo. While isLoading is on, the button sets aria-busy and keeps a visually hidden copy of its label, so a screen reader still hears what it does. A disabled button leaves the tab order unless you add focusableWhenDisabled, which marks it aria-disabled and keeps it focusable. Rendered as an a through the #render slot, it stays a link, with no button role, and is announced as one.
- Enter
- Presses the focused button.
- Space
- Presses the focused button when the key is released.
Demos
Size
Four pairs, from xs to lg, each an outline button with text beside its square icon-* twin holding an arrow. Pick the size from where the button sits: xs in a dense toolbar, sm in a table row or a card header, the default md in a form. A fifth pair, xl and icon-xl, is there for a landing page and isn't shown.
Variant default
The filled button in the theme's primary color, with no variant prop at all, since default is what Button falls back to. Give it to the one action the screen exists for, such as Save or Pay. Drop the actions around it to outline or ghost, so the eye lands in one place.
Outline
A bordered button on the page background, with a muted fill only on hover. Next to a filled Save it is the natural Cancel, and in a filter bar it reads as pressable without competing with the primary action. It keeps its border at rest, which is why it holds up better than ghost on a busy page.
Secondary
A filled button in the theme's quieter secondary color. Use it for an action that is real but not the preferred one, like Save as draft next to Publish, when both deserve a filled shape. If the second action should recede further, outline drops the fill altogether.
Ghost
No border and no background until the pointer is over it, so at rest the button is only its label. It suits repeated, low-stakes actions in a toolbar or a table row, where a dozen bordered buttons would turn into noise. Avoid it for the only action on a screen, since nothing marks it as pressable before someone hovers.
Destructive
The button in the theme's destructive color, for delete, remove and revoke. Put it on the button that confirms the deletion, inside the dialog, and keep the button that opens that dialog neutral. One red control in a group is enough for the danger to stand out.
Link
Text in the primary color that underlines on hover and is still a <button>, so it runs an action and doesn't navigate. Use it for a minor action under a form or inside a sentence, such as Forgot password or Resend code. When the press should change the URL, render a real link instead, as the As child demo does.
Icon
One outline button at icon-md with a circular arrow icon and no text. The icon is hidden from screen readers with aria-hidden, so aria-label, set to Submit, gives the button its name. Use an icon-only button for actions people know by their glyph, such as close, more or send, and keep a word on anything less obvious.
With icon
New Branch has a branch icon before its label, marked data-icon="inline-start", and Fork has its icon after, marked data-icon="inline-end". The attribute trims the padding on the icon's side so the button looks balanced, and because that padding is logical it flips in a right-to-left layout. Leave it off and the icon side keeps the full text padding.
Rounded
Get Started and an icon button, both with rounded-full added to their classes. The pill prop gives the same capsule without a class and also sets data-pill for your own styles. A capsule suits a call to action on a landing page or a round icon floating over content, while in app chrome a row of pills starts to look like tags.
Spinner
Generating and Downloading are disabled while a Spinner turns beside the label, before it on one and after it on the other. Keep the words on screen like this when people need to know which of several jobs is running. The isLoading prop is the other choice: it hides the label behind a centered spinner and keeps the button's width, as the next demo shows.
Loading
Save changes turns on isLoading for two seconds when pressed. The label stays in place but invisible, so the button keeps its width while a spinner turns over it, and the button is disabled with aria-busy set. Use it for a save or a submit that people wait on.
As child
Login is an a element in the #render slot of Button, with the slot's props bound on it, so it wears the small secondary button's classes and navigates like any link. UI SDK sees the href and leaves it a link, with no type or button role. Use this when pressing the control should change the URL, as with a sign-in or pricing page.
RTL
Five buttons in a row whose dir is rtl, four of them with Arabic text: outline, destructive, one with an arrow marked data-icon="inline-end", an icon button labelled Add, and a disabled one with a spinner. The arrow also carries rtl:rotate-180, so it points the way the text reads. Set dir on a container like this for a small island of right-to-left UI.
FAQ
How do I make a Button that links to another page in Vue?
Give Button a #render slot with an a in it and bind the slot's props on the a, as the As child demo does. UI SDK sees the href and leaves it a plain link with no type or button role. For Vue Router or Nuxt, use the custom form of RouterLink or NuxtLink, and bind the slot's props on your own a before its navigate, so a click on a disabled or loading button is stopped before the router sees it.
variant="link" only changes how a button looks, and a button with it still goes nowhere when pressed. To style an element that isn't a Button at all, call buttonVariants with a variant and size and put the classes it returns on that element.
Why doesn't my Button submit the form?
Button sets type to button unless you pass another value. A native button inside a form is a submit button by default, so without this every Cancel or Show password control would send the form. Set type to submit on the one button that should send it, and pressing Enter in a text field will submit through it as well.
While isLoading is on, the button is disabled, so a second press can't send the same form twice.
How do I show a loading spinner on a Button?
Set isLoading on Button, as the Loading demo does. The label stays in place but invisible, so the width doesn't jump, a Spinner is centered over it, and the button is disabled with aria-busy set. A hidden copy of the label keeps the name for screen readers.
To keep the words on screen, put a Spinner inside the button next to the text and disable the button yourself, as the Spinner demo does. A disabled native button can't hold focus, so add focusableWhenDisabled to keep focus on it while it loads. A Promise from @click keeps the button pending until it settles, ignoring presses, with no spinner.
As a link, it can't be followed while it loads, and shows the spinner only if the #render slot renders children.
What Button variants and sizes are there, and can I add my own?
variant takes default, secondary, outline, ghost, destructive and link. size takes xs, sm, md, lg and xl for a button with text, and icon-xs through icon-xl for a square icon button. shadcn/ui's default and icon sizes still work as other names for md and icon-md, and pill rounds any of them fully.
Both lists live in buttonVariants, a tailwind-variants tv call in the Button file you installed. Add a key under variant or size with its classes, and Button accepts the new value with its type checked.
How do I add an icon to a Button?
Put the icon inside Button, before or after the text, and mark it with data-icon set to inline-start or inline-end. The button's gap spaces the icon from the words, and the attribute trims the padding on that side, as the With icon demo shows. That padding is logical, so it flips in a right-to-left layout.
With no text, use an icon-* size, which keeps the button square, and give it an aria-label, as in the Icon demo. An icon takes the button's icon size unless it carries a size-* class of its own.
Why doesn't a Tooltip open on a disabled Button?
A disabled Button ignores the pointer completely. Its classes set pointer-events: none whenever it is disabled, so hovering it never reaches a Tooltip trigger. Put the tooltip on a wrapper instead, such as a span around the button, and give that wrapper a tab index of 0 so keyboard users can reach the explanation too.
Disabling is usually better than hiding: a missing button looks like a bug, while a disabled one with a reason shows the action exists. Adding focusableWhenDisabled keeps the button itself in the tab order, which lets a tooltip open on focus, though hover is still blocked.
How do I handle a Button click in Vue?
Listen with @click. It fires for a mouse click, a tap, and Enter or Space on the focused button, and a second argument says which of those it was. A disabled or loading button doesn't fire it.
For work that takes a while, turn on isLoading until the promise settles, so a second press can't start the same job again.
API Reference
Button
<button> data-slot="button"
clickEffect?boolean
Apply a click effect to the button.
- Default
true
debug?boolean
Logs every state change with its reason to the console, in development builds.
disabled?boolean
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.
- Default
false
focusableWhenDisabled?boolean
Keeps a disabled button in the tab order with aria-disabled instead of the native attribute, so it can hold focus while it becomes disabled and host a tooltip that says why. Presses still do nothing.
- Default
false
isLoading?boolean
Show a loading indicator.
- Default
false
pendingAnnouncement?string
What screen readers hear once the button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
- Default
"Loading"
pill?boolean
Fully rounded corners.
- Default
false
size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
The size.
- Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"- Default
"md"
type?"button" | "reset" | "submit"
What a native button does in a form: "submit" submits it and "reset" resets it. Ignored when the button renders as something else.
- Type
"button" | "reset" | "submit"- Default
"button"
variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
The visual style.
- Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"- Default
"default"
#render?{ props, state, children }
A slot that renders your own element: bind its props with v-bind="props". It also gets the part's state, and children, its content.
class?string
Merged with the part's classes.
@click( event: MouseEvent, details?: ButtonActionDetails ) → unknown
Runs when the button is pressed. Return a Promise to keep it pending
(data-pending) until it settles. details.source says how it was
pressed; a wrapper passing the click on may leave it out.
- Type
( event: MouseEvent, details?: ButtonActionDetails ) → unknown- Parameters
event– React.MouseEvent<HTMLButtonElement>details?– ButtonActionDetails- Returns
unknown
data-disabled?string
Present when disabled.
data-pending?string
Present while the Promise its press handler returned is running.
data-pill?string
Present when pill is set.
data-size?string
Mirrors size.
data-state?string
"loading" when isLoading is true, otherwise "idle".
data-variant?string
Mirrors variant.











