# Call to action (themes.dev UI block)

One heading, one line and one or two buttons, centred on an inverted panel: the closing ask before the footer. Black and white, dark mode, shadcn-compatible; React, Astro and plain HTML.

38% of 671 home pages and 37% of 151 landing pages we studied have a call-to-action section.

## Install

- React: `npx shadcn@latest add https://www.themes.dev/ui/r/call-to-action.json`
- Astro: `npx shadcn@latest add https://www.themes.dev/ui/r/astro/call-to-action.json`
- HTML: https://www.themes.dev/ui/r/html/call-to-action.html (with https://www.themes.dev/ui/r/html/caseroom.css)

Page: https://www.themes.dev/ui/blocks/call-to-action/ · Rules for agents: https://www.themes.dev/ui/AGENT.md

## Code

### call-to-action.astro

```astro
---
import Button from '@/components/ui/button.astro';
import { cn } from '@/lib/utils';
import { callToAction as c, type CallToActionContent } from './call-to-action.classes';

type Props = CallToActionContent & { class?: string };
const { title, description, primary, secondary, note, id, class: className } = Astro.props;
---

<section aria-labelledby={`${id}-title`} class={cn(c.root, className)}>
  <div class={c.panel}>
    <div class={c.text}>
      <h2 id={`${id}-title`} class={c.title}>{title}</h2>
      {description && <p class={c.description}>{description}</p>}
    </div>
    <div class={c.actions}>
      <Button href={primary.href} size="lg">{primary.label}</Button>
      {secondary && <Button href={secondary.href} size="lg" variant="outline">{secondary.label}</Button>}
    </div>
    {note && <p class={c.note}>{note}</p>}
  </div>
</section>
```

### call-to-action.classes.ts

```tsx
/** Call to action, centred: one heading, one line and one or two buttons, centred on an inverted panel (class inverted
 *  from the theme: the page's closing ground before the footer). The primary button keeps its own states on the
 *  inverted ground; the secondary is the outline button. Buttons stack full width below 24rem of the block's width. */
export const callToAction = {
  root: '@container bg-background px-6 py-16 text-foreground @3xl:py-24',
  panel: 'inverted mx-auto flex max-w-6xl flex-col items-center gap-8 rounded-xl bg-background px-6 py-14 text-center text-foreground @3xl:py-20',
  text: 'flex max-w-2xl flex-col items-center gap-4',
  title: 'text-3xl font-semibold tracking-[-0.03em] text-balance @2xl:text-4xl',
  description: 'max-w-xl text-base text-pretty text-muted-foreground @2xl:text-lg',
  actions: 'flex w-full flex-col gap-3 @sm:w-auto @sm:flex-row @sm:justify-center',
  note: 'text-sm text-muted-foreground',
};

export type CallToActionContent = {
  title: string;
  description?: string;
  primary: { href: string; label: string };
  secondary?: { href: string; label: string };
  /** A short line under the buttons ("No card needed"). */
  note?: string;
  /** Unique on the page; ids the heading. */
  id: string;
};
```

### call-to-action.tsx

```tsx
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import { callToAction as c, type CallToActionContent } from './call-to-action.classes';

export type CallToActionProps = CallToActionContent & { className?: string };

/** A centred call to action on an inverted panel: heading, one line, one or two buttons and an optional note. */
export function CallToAction({ title, description, primary, secondary, note, id, className }: CallToActionProps) {
  return (
    <section aria-labelledby={`${id}-title`} className={cn(c.root, className)}>
      <div className={c.panel}>
        <div className={c.text}>
          <h2 id={`${id}-title`} className={c.title}>{title}</h2>
          {description && <p className={c.description}>{description}</p>}
        </div>
        <div className={c.actions}>
          <Button href={primary.href} size="lg">{primary.label}</Button>
          {secondary && <Button href={secondary.href} size="lg" variant="outline">{secondary.label}</Button>}
        </div>
        {note && <p className={c.note}>{note}</p>}
      </div>
    </section>
  );
}
```
