Docs
Button
Button
Displays a button or a component that looks like a button.
Installation
pnpm dlx shadcn@latest add button
Usage
import { Button } from "@/components/ui/button"
<Button variant="outline">Button</Button>
Link
You can use the buttonVariants
helper to create a link that looks like a button.
import { buttonVariants } from "@/components/ui/button"
<Link className={buttonVariants({ variant: "outline" })}>Click here</Link>
Alternatively, you can set the asChild
parameter and nest the link component.
<Button asChild>
<Link href="/login">Login</Link>
</Button>
Examples
Primary
Secondary
Destructive
Outline
Ghost
Link
Icon
With Icon
Loading
As Child
Changelog
2024-10-16 Classes for icons
Added gap-2 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0
to the button to automatically style icon inside the button.
Add the following classes to the cva
call in your button.tsx
file.
button.tsx
const buttonVariants = cva(
"inline-flex ... gap-2 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0"
)