Docs
Button

Button

Displays a button or a component that looks like a button.

Installation

Copy and paste the following code into your project.

import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
 
import { cn } from "@/lib/utils"
 
const buttonVariants = cva(
  "inline-flex select-none items-center justify-center font-medium outline-offset-2 transition focus-visible:outline focus-visible:outline-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
  {
    variants: {
      variant: {
        primary: "bg-primary text-primary-foreground hover:bg-primary/90",
        destructive:
          "bg-destructive text-destructive-foreground hover:bg-destructive/90",
        outline:
          "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
        secondary:
          "bg-secondary text-secondary-foreground hover:bg-secondary/80",
        ghost: "hover:bg-accent hover:text-accent-foreground",
        link: "text-primary underline-offset-4 hover:underline",
        none: "",
      },
      size: {
        sm: "h-8 gap-1.5 rounded-sm px-3 text-xs",
        md: "h-9 gap-2 rounded-md px-4 text-sm",
        lg: "h-10 gap-2.5 rounded-lg px-8 text-base",
        "icon-sm": "size-8 rounded-sm",
        "icon-md": "size-9 rounded-md",
        "icon-lg": "size-10 rounded-lg",
      },
    },
    defaultVariants: {
      variant: "primary",
      size: "md",
    },
  },
)
 
export interface ButtonProps
  extends React.ButtonHTMLAttributes<HTMLButtonElement>,
    VariantProps<typeof buttonVariants> {}
 
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, variant, size, ...props }, ref) => (
    <button
      className={cn(buttonVariants({ variant, size, className }))}
      ref={ref}
      {...props}
    />
  ),
)
Button.displayName = "Button"
 
export { Button, buttonVariants }

Update the import paths to match your project setup.

Usage

import { Button } from "@/components/ui/button"
<Button variant="outline">Button</Button>

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>

Examples

Primary

Secondary

Destructive

Outline

Ghost

Icon

With Icon

Loading