---
title: "Citations"
description: "Inline citation markers paired with a collapsible, progressively rendered reference collection for grounded agent responses."
category: "AI Agents"
publishedAt: "2026-08-01"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/components/agents/citations"
markdown: "https://beui.dev/components/agents/citations.md"
license: "MIT"
---

# Citations

> Inline citation markers paired with a collapsible, progressively rendered reference collection for grounded agent responses.

## Install

```bash
npx shadcn@latest add @beui/citations
```

## Dependencies

- `clsx`
- `lucide-react`
- `motion`
- `react`
- `tailwind-merge`

## Usage

```tsx
"use client";

import { FileText, RotateCcw } from "lucide-react";
import { useReducedMotion } from "motion/react";
import { useEffect, useState } from "react";
import {
  Citation,
  Citations,
  type CitationItem,
} from "@/components/agents/citations";

const CITATION_ITEMS: CitationItem[] = [
  {
    id: "motion",
    title: "Motion documentation",
    domain: "motion.dev",
    url: "https://motion.dev/docs/react",
  },
  {
    id: "wai",
    title: "WAI accessibility patterns",
    domain: "w3.org",
    url: "https://www.w3.org/WAI/ARIA/apg/",
  },
  {
    id: "guidelines",
    title: "Motion guidelines",
    domain: "Design handbook · PDF",
    icon: <FileText />,
  },
];

function CitationsDemo() {
  const reduce = useReducedMotion() ?? false;
  const [visible, setVisible] = useState(reduce ? CITATION_ITEMS.length : 0);

  useEffect(() => {
    if (reduce) return;
    const timers = CITATION_ITEMS.map((_, index) =>
      window.setTimeout(() => setVisible(index + 1), 500 + index * 700),
    );
    return () => timers.forEach(window.clearTimeout);
  }, [reduce]);

  return (
    <div className="space-y-4">
      <p className="text-sm leading-6 text-foreground/90">
        Use layout-aware motion for newly appended results{" "}
        <Citation citationId="motion" index={1} idPrefix="preview-source" /> and preserve accessible
        disclosure behavior <Citation citationId="wai" index={2} idPrefix="preview-source" /> as the list
        grows, keeping exits shorter than entrances{" "}
        <Citation
          citationId="guidelines"
          index={3}
          idPrefix="preview-source"
          label="Citation 3: Motion guidelines"
        />
        .
      </p>
      <Citations
        idPrefix="preview-source"
        citations={CITATION_ITEMS.slice(0, visible)}
        defaultOpen
      />
    </div>
  );
}

export function CitationsPreview() {
  const [run, setRun] = useState(0);

  return (
    <div className="relative h-[410px] w-full max-w-lg">
      <CitationsDemo key={run} />
      <button
        type="button"
        onClick={() => setRun((value) => value + 1)}
        className="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
      >
        <RotateCcw className="size-3" />
        Replay
      </button>
    </div>
  );
}
```

## API Reference

### Citation

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `citationId` | `string` |  | Yes | Id of the `CitationItem` this marker links to. |
| `index` | `number` |  | Yes | Number shown on the marker. |
| `idPrefix` | `string` |  | Yes | Must match the related Citations idPrefix. |
| `label` | `string` |  | No | Accessible name for the marker. Defaults to `View citation {index}`. Include the index so voice control users can say the number they see. |
| `className` | `string` |  | No | Classes merged onto the marker link. |

### CitationFavicon

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `url` | `string` |  | No | Page whose site favicon is shown. A globe icon shows when absent or broken. |
| `icon` | `ReactNode` |  | No | Drawn instead of the favicon when truthy. |
| `className` | `string` |  | No | Classes merged onto the root element. |

### CitationStack

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `citations` | `CitationItem[]` |  | Yes | Sources whose favicons are stacked. |
| `limit` | `number` | `3` | No | Most favicons to show. Default: 3 |
| `className` | `string` |  | No | Classes merged onto the root element. |

### CitationList

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `citations` | `CitationItem[]` |  | Yes | Sources listed in order, numbered from 1. |
| `idPrefix` | `string` |  | No | Prefix for row ids that `Citation` markers link to. Generated when omitted. |
| `highlightedId` | `string` |  | No | The citation a marker just led to; its row is lit. |
| `className` | `string` |  | No | Classes merged onto the root element. |

### Citations

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `citations` | `CitationItem[]` |  | Yes | Sources listed in order, numbered from 1. |
| `title` | `ReactNode` |  | No | Text of the toggle button. Default: "Sources" |
| `open` | `boolean` |  | No | Whether the list is expanded, for controlled use. |
| `defaultOpen` | `boolean` | `false` | No | Whether the list starts expanded when uncontrolled. Default: false |
| `onOpenChange` | `((open: boolean) => void)` |  | No | Called with the new state when the list expands or collapses. |
| `idPrefix` | `string` |  | No | Prefix for row ids that `Citation` markers link to. Generated when omitted. |
| `className` | `string` |  | No | Classes merged onto the root element. |
| `labels` | `Partial<{ title: string; viewCitation: string; }>` |  | No | Override any built-in string. |

## Types

### CitationItem

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Unique key for the source, matched by a `Citation` marker's `citationId`. |
| `title` | `ReactNode` | Yes | Source name shown as the row's main text. |
| `domain` | `ReactNode` | No | Muted text after the title, such as the site's host. |
| `url` | `string` | No | Link opened in a new tab and the favicon source. Omit for a plain row. |
| `icon` | `ReactNode` | No | Replaces the URL favicon, e.g. a document icon for non-web sources. An svg child is sized to match the favicon; falsy values fall back to the favicon. |

## Composition

Pair inline citation markers with a source disclosure owned by the same response.

```text
StreamingResponse
├── Citation
└── Citations
    ├── CitationStack
    └── CitationList
```

- `streaming-response`: Reveals the source summary when the answer completes.
- `message`: Keeps cited answers within a semantic conversation row.

### How it works

Citations connect a claim to supporting material without interrupting the answer. Inline markers should stay lightweight while the source collection provides enough information to inspect the evidence.

- **Mark the claim.** A compact inline reference stays attached to the statement it supports.
- **Collect sources.** Repeated references resolve into a concise source summary below the response.
- **Inspect evidence.** The disclosure opens real destinations without replacing or obscuring the answer.

### What it owns and what it leaves to you

- **Owns:** Inline markers, source identity presentation, favicon resolution, and collection disclosure.
- **Leaves to the app:** Retrieval, ranking, citation correctness, and URL trust decisions to the application.

### Principles

- **Keep claims readable.** Markers sit with the relevant text and remain compact enough that they do not become the dominant visual element.
- **Use real destinations.** Source labels, hosts, and favicons derive from the supplied URLs rather than a fixed catalog of known websites. Non-web sources such as documents or records can pass their own icon instead.
- **Disclose the collection.** A compact source summary opens into the complete list while preserving the response layout above it.

### Use it when

A generated answer makes grounded claims that readers may need to verify against supplied URLs.

### Avoid it when

Links are ordinary navigation, sources cannot be tied to claims, or the application has not validated the destinations.

## About Citations

Citations is a set of React components for grounding AI answers in sources. Citation renders a small numbered inline marker that links to its source, and Citations renders a collapsible Sources list with each source's favicon, title, domain and matching number. CitationList and CitationStack are exported for custom layouts, and rows animate in with Framer Motion as sources stream.

### When to use it

- A retrieval or RAG chatbot needs to show which documents support each claim.
- A web search assistant lists the pages it read, with favicons, so readers can open them.
- An internal knowledge tool cites files or notes that have no URL and shows a custom icon instead of a favicon.

### Accessibility

Inline markers are links named "View citation 1" and so on by default; the label prop overrides this, and keeping the number in it lets voice control users say what they see. Each marker links to its source row by id, and rows with a URL are links that open in a new tab with noopener. The Sources toggle is a button with aria-expanded and aria-controls, and favicons are decorative. With reduced motion enabled, rows appear and leave without sliding and the list opens instantly.

### FAQ

**How do I add citations to AI responses in React?**

Place Citation inline with a citationId, an index and an idPrefix, then render Citations below the answer with the same citations array and the same idPrefix so each marker links to its row.

**Where do the source favicons come from?**

They are derived from each CitationItem's url. If a favicon fails to load, a globe icon is shown instead, and you can pass icon on an item to replace the favicon, for example with a document icon.

**Can I control whether the sources list is open?**

Yes. Pass open and onOpenChange for controlled use, or defaultOpen for uncontrolled use (closed by default). The title prop renames the "Sources" label.

## React Native

A React Native version ships in beUI Native. The detail JSON has every file to copy.

```bash
npx expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-svg react-native-worklets
npm install uniwind tailwindcss
```

- Native detail: https://beui.dev/native/r/citations
- GitHub: https://github.com/starc007/beui-native/tree/main/src/components/citations

## Source

- Registry detail: https://beui.dev/r/citations
- Raw source: https://beui.dev/r/citations/raw
- GitHub: https://github.com/starc007/ui-components
