# Testimonial (themes.dev UI block)

One quote, large, with the person under it: a face, their name and their role. Initials stand in when there is no photo. Black and white, dark mode, shadcn-compatible; React, Astro and plain HTML.

16% of 671 home pages and 15% of 151 landing pages we studied have a testimonials section.

## Install

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

Page: https://www.themes.dev/ui/blocks/testimonial/ · Rules for agents: https://www.themes.dev/ui/AGENT.md

## Code

### testimonial.astro

```astro
---
import { cn } from '@/lib/utils';
import { initialsOf, testimonial as c, type TestimonialContent } from './testimonial.classes';

type Props = TestimonialContent & { class?: string };
const { quote, name, role, photo, label = 'What customers say', id, class: className } = Astro.props;
---

<section aria-labelledby={`${id}-title`} class={cn(c.root, className)}>
  <div class={c.inner}>
    <h2 id={`${id}-title`} class={c.heading}>{label}</h2>
    <figure class={c.figure}>
      <blockquote class={c.quote}><p>“{quote}”</p></blockquote>
      <figcaption class={c.caption}>
        <span class={c.face}>
          {
            photo ? (
              <img src={photo.src} width={photo.width ?? 112} height={photo.height ?? 112} alt="" loading="lazy" decoding="async" class={c.photo} />
            ) : (
              <span aria-hidden="true" class={c.initials}>{initialsOf(name)}</span>
            )
          }
        </span>
        <span class={c.person}>
          <cite class={c.name}>{name}</cite>
          {role && <span class={c.role}>{role}</span>}
        </span>
      </figcaption>
    </figure>
  </div>
</section>
```

### testimonial.classes.ts

```tsx
/** Testimonial, single: one quote, large, with the person under it (a face, their name, their role and company). A
 *  <figure> with a <blockquote> and a <figcaption>. The portrait is decorative (alt="") because the name is right beside
 *  it; without a photo the person's initials stand in. The section has a visually hidden heading so it shows up in the
 *  page outline. */
export const testimonial = {
  root: '@container bg-background px-6 py-16 text-foreground @3xl:py-24',
  inner: 'mx-auto max-w-3xl',
  heading: 'sr-only',
  figure: 'm-0 flex flex-col gap-8',
  quote: 'm-0 text-2xl leading-snug font-medium tracking-[-0.02em] text-balance @2xl:text-3xl',
  caption: 'flex items-center gap-4',
  face: 'size-14 shrink-0 overflow-hidden rounded-full bg-muted ring-1 ring-border',
  photo: 'size-full object-cover grayscale',
  initials: 'flex size-full items-center justify-center text-base font-medium text-muted-foreground',
  person: 'flex min-w-0 flex-col',
  name: 'text-base font-semibold not-italic',
  role: 'text-sm text-muted-foreground',
};

export type TestimonialContent = {
  quote: string;
  name: string;
  /** Role and company, one line ("Head of product, Ostra"). */
  role?: string;
  /** A square portrait; at least 112px for the 56px circle on a 2x screen. */
  photo?: { src: string; width?: number; height?: number };
  /** The hidden section heading. */
  label?: string;
  /** Unique on the page; ids the heading. */
  id: string;
};

/** "Maren Holt" → "MH". */
export const initialsOf = (name: string) =>
  name
    .split(/\s+/)
    .filter(Boolean)
    .slice(0, 2)
    .map((p) => p[0]!.toUpperCase())
    .join('');
```

### testimonial.tsx

```tsx
import { cn } from '@/lib/utils';
import { initialsOf, testimonial as c, type TestimonialContent } from './testimonial.classes';

export type TestimonialProps = TestimonialContent & { className?: string };

/** One quote, large, with the person under it: a face, their name and their role. */
export function Testimonial({ quote, name, role, photo, label = 'What customers say', id, className }: TestimonialProps) {
  return (
    <section aria-labelledby={`${id}-title`} className={cn(c.root, className)}>
      <div className={c.inner}>
        <h2 id={`${id}-title`} className={c.heading}>{label}</h2>
        <figure className={c.figure}>
          <blockquote className={c.quote}><p>“{quote}”</p></blockquote>
          <figcaption className={c.caption}>
            <span className={c.face}>
              {photo ? (
                <img src={photo.src} width={photo.width ?? 112} height={photo.height ?? 112} alt="" loading="lazy" decoding="async" className={c.photo} />
              ) : (
                <span aria-hidden="true" className={c.initials}>{initialsOf(name)}</span>
              )}
            </span>
            <span className={c.person}>
              <cite className={c.name}>{name}</cite>
              {role && <span className={c.role}>{role}</span>}
            </span>
          </figcaption>
        </figure>
      </div>
    </section>
  );
}
```
