---
title: Call to Action Button
description: "Call to action (CTA) buttons drive conversions with a larger surface and hover effects. Built for Astro, Shadcn, and Tailwind CSS."
seo:
    title: "Shadcn Call to Action Button for Astro"
related:
    - /components/button
    - /components/link
    - /blocks/cta
    - /blocks/hero
sidebar:
    label: "Call to Action Button"
    badge: "new"
---

```astro
---
import { CtaButton, type CtaButtonProps } from "@/components/ui/cta-button"
import CTAButtonEffectToggle from "@/components/previews/cta-button-effect-toggle.astro"

/** Same value as `defaultValue` on the effect toggle. */
const initialEffect = "slide"

const effects: NonNullable<CtaButtonProps["effect"]>[] = [
  "expand-swap",
  "slide",
  "expand",
]

const variants: NonNullable<CtaButtonProps["variant"]>[] = [
  "default",
  "secondary",
  "outline",
]
---

<div
  class="flex flex-col items-center justify-center gap-8"
  data-cta-effect-demo
>
  <CTAButtonEffectToggle />
  <div class="flex flex-wrap items-center justify-center gap-8">
    {variants.map((variant) =>
      effects.map((effect) => (
        <CtaButton
          variant={variant}
          effect={effect}
          data-cta-effect-item
          data-active-effect={effect === initialEffect ? "true" : "false"}
          class="data-[active-effect=false]:hidden"
        >
          Call to Action
        </CtaButton>
      )),
    )}
  </div>
</div>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/cta-button
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/cta-button/cta-button-variants.ts

```ts
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from 'cn'

import { buttonVariants } from '../button/button-variants.ts'

const ctaStyles = cva(
    "group/cta-button isolate h-(--cta-height) gap-3 rounded-xl border p-[calc(var(--cta-inset)-1px)] ps-3 pe-[calc(var(--cta-icon-size)+var(--cta-inset)+(--spacing(3))-1px)] text-lg font-medium [--cta-icon-size:calc(var(--cta-height)-var(--cta-inset)*2)] [--cta-inset:--spacing(1)] before:rounded-[calc(var(--radius-xl)-1px)] after:absolute sm:text-lg [&_svg:not([class*='size-'])]:size-5 sm:[&_svg:not([class*='size-'])]:size-5",
    {
        variants: {
            variant: {
                default:
                    '[--cta-fill:var(--primary-foreground)] [--cta-ink:var(--primary)]',
                secondary:
                    '[--cta-fill:var(--secondary-foreground)] [--cta-ink:var(--background)]',
                outline:
                    '[--cta-fill:var(--foreground)] [--cta-ink:var(--background)]',
                inverse:
                    'border-border bg-primary-foreground text-primary [--cta-fill:var(--primary)] [--cta-ink:var(--primary-foreground)]',
            },
            effect: {
                expand: null,
                'expand-swap':
                    '[--cta-label-shift:calc(var(--cta-icon-size)+var(--cta-inset)-1px)]',
                slide: null,
            },
            size: {
                default: '[--cta-height:--spacing(10)]',
                lg: '[--cta-height:--spacing(12)]',
                xl: 'min-w-24 text-xl [--cta-height:--spacing(14)] sm:text-xl',
            },
        },
        defaultVariants: {
            variant: 'default',
            effect: 'expand',
            size: 'default',
        },
    },
)

export type CtaButtonVariantProps = VariantProps<typeof ctaStyles>

/** Use the project's Button recipe with the CTA's own sizes and icon treatment. */
export const ctaButtonVariants = ({
    variant = 'default',
    effect = 'expand',
    size = 'default',
}: CtaButtonVariantProps = {}) =>
    cn(
        buttonVariants({
            variant: variant === 'inverse' ? null : variant,
            size: null,
        }),
        ctaStyles({ variant, effect, size }),
    )
```

#### src/components/ui/cta-button/cta-button.astro

```astro
---
import type { Polymorphic } from "astro/types"
import ArrowRight from "@lucide/astro/icons/arrow-right"
import { cn } from "cn"

import { ctaButtonVariants } from "./cta-button-variants.ts"
import type { CtaButtonProps } from "./types.ts"

type Props<Tag extends "a" | "button" = "button"> = Polymorphic<{ as: Tag }> &
  CtaButtonProps

const {
  as: Tag = "href" in Astro.props ? "a" : "button",
  class: className,
  variant = "default",
  effect = "expand",
  size = "default",
  ...props
} = Astro.props

const elementProps: Record<string, unknown> = {
  ...(Tag === "button" ? { type: "button" as const } : {}),
  ...props,
}
---

<Tag
  data-slot="cta-button"
  data-variant={variant}
  data-effect={effect}
  data-size={size}
  class={cn(ctaButtonVariants({ variant, effect, size }), className)}
  {...elementProps}
>
  <span
    data-slot="cta-button-label"
    class={cn(
      "relative z-10 transition-colors duration-300 ease-[cubic-bezier(0.32,0.72,0,1)]",
      effect !== "slide" &&
        "group-hover/cta-button:text-(--cta-ink) group-focus-visible/cta-button:text-(--cta-ink)",
      effect === "expand-swap" &&
        "transition-[color,translate] group-hover/cta-button:translate-x-(--cta-label-shift) group-focus-visible/cta-button:translate-x-(--cta-label-shift) rtl:group-hover/cta-button:-translate-x-(--cta-label-shift) rtl:group-focus-visible/cta-button:-translate-x-(--cta-label-shift)",
    )}
  >
    <slot />
  </span>
  <span
    data-slot="cta-button-icon"
    data-icon="inline-end"
    aria-hidden="true"
    class={cn(
      "pointer-events-none absolute inset-y-[calc(var(--cta-inset)-1px)] inset-e-[calc(var(--cta-inset)-1px)] z-0 w-(--cta-icon-size) rounded-[max(0px,calc(var(--radius-xl)-var(--cta-inset)))] bg-(--cta-fill) text-(--cta-ink)",
      effect === "slide"
        ? "overflow-hidden"
        : "transition-[width] duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] group-hover/cta-button:w-[calc(100%-(var(--cta-inset)-1px)*2)] group-focus-visible/cta-button:w-[calc(100%-(var(--cta-inset)-1px)*2)]",
    )}
  >
    <span
      data-slot="cta-button-arrow"
      class={cn(
        "absolute inset-y-0 inset-e-0 inline-flex w-(--cta-icon-size) items-center justify-center",
        effect === "expand-swap" && "inset-e-auto inset-s-0",
        effect === "slide" &&
          "transition-transform duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] group-hover/cta-button:translate-x-full group-hover/cta-button:-translate-y-full group-focus-visible/cta-button:translate-x-full group-focus-visible/cta-button:-translate-y-full rtl:group-hover/cta-button:-translate-x-full rtl:group-focus-visible/cta-button:-translate-x-full",
      )}
    >
      <slot name="icon">
        <ArrowRight
          class={cn(
            effect === "expand" &&
              "rotate-0 group-hover/cta-button:-rotate-45 group-focus-visible/cta-button:-rotate-45 transition-transform",
            effect === "expand-swap" &&
              "-rotate-45 transition-transform duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] group-hover/cta-button:rotate-0 group-focus-visible/cta-button:rotate-0",
            effect === "slide" && "-rotate-45 rtl:-rotate-135",
          )}
        />
      </slot>
    </span>
    {effect === "slide" && (
      <span
        data-slot="cta-button-arrow-copy"
        class="absolute inset-y-0 inset-e-0 inline-flex w-(--cta-icon-size) -translate-x-full translate-y-full items-center justify-center transition-transform duration-300 ease-[cubic-bezier(0.32,0.72,0,1)] group-hover/cta-button:translate-x-0 group-hover/cta-button:translate-y-0 group-focus-visible/cta-button:translate-x-0 group-focus-visible/cta-button:translate-y-0 rtl:translate-x-full rtl:group-hover/cta-button:translate-x-0 rtl:group-focus-visible/cta-button:translate-x-0"
      >
        <slot name="icon">
          <ArrowRight class="-rotate-45 rtl:-rotate-135" />
        </slot>
      </span>
    )}
  </span>
</Tag>
```

#### src/components/ui/cta-button/index.ts

```ts
export { default as CtaButton } from './cta-button.astro'
export {
    ctaButtonVariants,
    type CtaButtonVariantProps,
} from './cta-button-variants.ts'
export type { CtaButtonProps } from './types.ts'
```

#### src/components/ui/cta-button/types.ts

```ts
/** Props for a call to action with a label and a decorative icon. */
export interface CtaButtonProps {
    /**
     * The color treatment. `inverse` uses primary text on a primary-foreground
     * background with a primary icon fill.
     * @default 'default'
     */
    variant?: 'default' | 'secondary' | 'outline' | 'inverse'
    /**
     * The hover and keyboard focus effect. `expand` grows the icon fill;
     * `expand-swap` also moves the icon to the leading edge; `slide` replaces the
     * icon with a second copy that enters diagonally.
     * @default 'expand'
     */
    effect?: 'expand' | 'expand-swap' | 'slide'
    /**
     * The button and icon container size.
     * @default 'default'
     */
    size?: 'default' | 'lg' | 'xl'
}
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```astro
---
import { CtaButton } from "@/components/ui/cta-button"
---

<CtaButton>Get started</CtaButton>
<CtaButton variant="inverse" effect="expand-swap">Book a demo</CtaButton>
<CtaButton variant="secondary" effect="slide">Launch project</CtaButton>
```

Put the label in the default slot. The component adds a right arrow inside
`span[data-slot="cta-button-icon"]`. The icon is decorative and is hidden from
assistive technology. Keep a visible text label that describes the action.

The root uses `data-slot="cta-button"`. It shares the selected preset's Button
recipe, with larger sizes and a separate icon background.

Use `variant` for color and `effect` for motion. Every effect works with
`default`, `secondary`, `outline`, and `inverse`. The `inverse` color variant
uses primary text and an icon fill on a primary-foreground background.

| Effect | Hover and keyboard focus behavior |
| ------ | --------------------------------- |
| `expand` | Expands the icon background behind the label. This is the default. |
| `expand-swap` | Expands the fill and moves the icon to the opposite side of the label. |
| `slide` | Slides the icon out diagonally as a second copy enters. |

The inset stays at 4 pixels with the default spacing scale. Each effect keeps
the button width fixed, so nearby content does not move. These effects use CSS
and do not need Motion. With reduced motion enabled, the state changes without
animation.

## Examples

### Expand and swap sides

Use `effect="expand-swap"` to move the icon from the trailing edge to the leading edge
on hover or keyboard focus. The label moves in the opposite direction, and the
arrow turns from diagonal to horizontal. Use `variant="inverse"` for the
primary fill shown in the first example.

The button keeps its width. The motion follows the text direction and works
with all sizes, rounded corners, and a custom icon. Only the default arrow rotates.

```astro
---
import { CtaButton } from "@/components/ui/cta-button"
---

<div class="flex flex-wrap items-center justify-center gap-4">
  <CtaButton variant="inverse" effect="expand-swap">
    Book a demo
  </CtaButton>
  <CtaButton variant="secondary" effect="expand-swap" size="lg">
    Book a demo
  </CtaButton>
  <CtaButton
    variant="outline"
    effect="expand-swap"
    size="xl"
    class="rounded-full"
  >
    Book a demo
  </CtaButton>
</div>
```

### Slide the icon

Use `effect="slide"` to move the icon out through the upper trailing corner.
A second copy enters from the lower opposite corner. The icon background clips
both copies. The label and background stay in place.

The direction follows the text direction. Use the `icon` slot to supply a
custom icon; the component renders both copies.

```astro
---
import { CtaButton } from "@/components/ui/cta-button"
---

<div class="flex flex-wrap items-center justify-center gap-4">
  <CtaButton effect="slide" class="rounded-full [--radius-xl:9999px]">
    Launch project
  </CtaButton>
  <CtaButton variant="secondary" effect="slide">
    View projects
  </CtaButton>
  <CtaButton variant="outline" effect="slide" size="lg">
    Explore projects
  </CtaButton>
</div>
```

### Sizes

Use `default`, `lg`, or `xl`. Their heights are 40, 48, and 56 pixels at the
default root font size. The default size is `default`.

All effects use 12 pixels of padding at the label edge and a 12-pixel gap
between the label and icon, with the default spacing scale. This spacing stays
the same across sizes. The icon container uses the button radius minus its
inset to keep the corners aligned.

```astro
---
import { CtaButton } from "@/components/ui/cta-button"
---

<div class="flex flex-wrap items-center justify-center gap-4">
  <CtaButton size="default">Default</CtaButton>
  <CtaButton size="lg">Large</CtaButton>
  <CtaButton size="xl">Extra large</CtaButton>
</div>
```

### Fully rounded

Use `rounded-full` with `[--radius-xl:9999px]` to keep the button, icon container,
and border effects fully rounded. The radius override applies only to this button.

```astro
---
import { CtaButton } from "@/components/ui/cta-button"
---

<div class="flex flex-wrap items-center justify-center gap-4">
  <CtaButton class="rounded-full [--radius-xl:9999px]">Get started</CtaButton>
  <CtaButton variant="secondary" class="rounded-full [--radius-xl:9999px]">
    View plans
  </CtaButton>
  <CtaButton variant="outline" class="rounded-full [--radius-xl:9999px]">
    Learn more
  </CtaButton>
</div>
```

### Link and custom icon

Use `as="a"` and `href` for a destination. Use the named `icon` slot to replace
the arrow. Supply only the icon; the component provides its span and background.
The `slide` effect repeats the same icon without changing its rotation.

```astro
---
import ArrowUpRight from "@lucide/astro/icons/arrow-up-right"
import { CtaButton } from "@/components/ui/cta-button"
---

<CtaButton as="a" href="/docs/installation" effect="slide">
  Start building
  <ArrowUpRight slot="icon" />
</CtaButton>
```

### Disabled

Use `disabled` on a button to stop activation. Native anchors do not support
`disabled`.

```astro
---
import { CtaButton } from "@/components/ui/cta-button"
---

<div class="flex flex-wrap items-center justify-center gap-4">
  <CtaButton disabled>Get started</CtaButton>
  <CtaButton variant="inverse" effect="expand-swap" disabled>
    Book a demo
  </CtaButton>
  <CtaButton effect="slide" disabled>
    Launch project
  </CtaButton>
</div>
```

## Props

### CtaButtonProps

<AutoTypeTable
    path="../../packages/ui/src/components/ui/cta-button/types.ts"
    name="CtaButtonProps"
/>

Use `as="button"` or `as="a"` to select the native element. Without `as`, an
`href` selects an anchor; otherwise the component renders a button with
`type="button"`. Set `type="submit"` for a form action. Native attributes and
`class` pass through to the root element.

## Slots

| Slot    | Content                                                |
| ------- | ------------------------------------------------------ |
| Default | The visible action label.                              |
| `icon`  | A decorative icon. Defaults to a right arrow.           |

## Theme and layout

The call to action shares the selected preset’s [Button](/components/button) recipe and keeps its own icon treatment. Choose a size that fits the label and surrounding section. Use a link for a destination and a button for an action. A complete [call to action block](/blocks/cta) can add supporting content around the control.
