Link Button

A link that looks like a button: an anchor styled with stock buttonVariants, never a button, so navigation keeps its link semantics. Takes Button's variant and size; size lg sets a 16px label. Pass render to use your framework's link, such as Next.js Link.

Installation

npx shadcn@latest add @01orbital/link-button

Usage

import { LinkButton } from "@/components/link-button/link-button"
import { DemoLabel } from "@/components/text/demo-label"

const COPY = { label: "Get started" } as const

const VARIANTS = [
  "default",
  "outline",
  "secondary",
  "ghost",
  "destructive",
  "link",
] as const
const SIZES = ["xs", "sm", "default", "lg"] as const

// Every variant at the default size, then every size in the default variant.
const EXAMPLES = [
  ...VARIANTS.map((variant) => ({
    caption: `Variant ${variant}`,
    props: { variant },
  })),
  ...SIZES.map((size) => ({ caption: `Size ${size}`, props: { size } })),
]

/** Link Button in every variant and every size. */
export default function LinkButtonDemo() {
  return (
    <div className="flex flex-wrap items-start gap-6 p-6">
      {EXAMPLES.map(({ caption, props }) => (
        <div key={caption} className="grid justify-items-start gap-4">
          <LinkButton href="#" {...props}>
            {COPY.label}
          </LinkButton>
          <DemoLabel>{caption}</DemoLabel>
        </div>
      ))}
    </div>
  )
}

This example installs with everything it uses:

npx shadcn@latest add @01orbital/link-button-demo

API reference

A link that looks like a button: an <a> with the button's look, never a button. Base UI's Button gives any element role="button", so navigation uses this instead.

variant and size are stock Button's; lg sets a 16px label. Pass render to use your framework's link, such as render={<Link href="/pricing" />} with Next.js, or change the default here once and every block follows.

It accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders, and the props of the stock Button it builds on.

Dependencies

npm: @base-ui/react, class-variance-authority, cn. The CLI installs them for you.

Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:

The shadcn parts here are their Base UI versions, and this piece uses Base UI's API. A Radix version you already have won't work with it.

Used in blocks

90 blocks are built with Link Button; the first 12:

Last updated on