# Chat Source

A citation chip linking to a source referenced in an answer.

- Category: AI & Agents
- Page: https://wunderui.com/components/chat-source
- Tier: Core and Pro

## Install

Chat Source ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { ChatSource } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { ChatSource } from "@wunderui/react"

export function Cited() {
  return <ChatSource index={1} title="Q3 revenue report" domain="wunderui.com" href="https://wunderui.com" />
}
```

Expected result: You see a small card with the number 1 in a grey circle, a globe, the title Q3 revenue report and wunderui.com under it. Press it and the address opens in a new tab.

## When to use

### Use Chat Source for

- A source an answer cites, with the number of its citation
- A link to the page or document an answer comes from
- A short row of sources under a finished reply

### Use something else

- [Source List](https://wunderui.com/components/source-list) for a numbered, pinned list of all the sources of an answer
- [Chat Attachment](https://wunderui.com/components/chat-attachment) for a file the person attached, not a page the answer cites
- [Chat Message](https://wunderui.com/components/chat-message) for the bubble that holds the answer and the citations in its text

## Keyboard

The card is a native link, so the browser handles focus and activation.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the next or previous source. Focus shows as an indigo border with a 2 px ring. |
| `Enter` | Follows the link: opens the address in a new tab, or, with the default `#`, calls `onClick` and stays on the page. A link does not react to Space. |

## Behavior

What the card does with its link, its text, assistive technology and motion.

- **Link:** A real address opens in a new tab with no referrer, and the click handler runs before the page opens. With the default placeholder it prevents navigation, so the page does not jump to the top.
- **Name:** The accessible name is the text inside the link: the number, the title and the domain, in that order. There is no extra label and no hint that the link opens a new tab.
- **Numbering:** The number is text inside the card and does not find the marker in your answer. Write the marker in the text yourself and keep the two numbers in step.
- **Truncation:** The title and the domain stay on one line each and are cut at the end. The card takes the width it is given, so a flex child needs a maximum width or a column to truncate in.
- **Live region:** The card is not a live region. When sources arrive after the answer, add a status line that counts them, in the page before it has text.
- **States:** Hover fills the card with the page tone and pressing with the subtle tone. Focus is an indigo border with a 2 px ring.
- **Motion:** None. Colours change at once and nothing moves, so there is nothing to reduce.

## Anatomy

- `ChatSource`: A link drawn as a card with a 1 px border and an 8 px radius. A real address opens in a new tab, while the default placeholder only calls the click handler.
- `Number`: A 16 px round badge with the citation number in 10 px semibold text. It is left out without a number.
- `Icon`: A 14 px globe in the tertiary text colour. It is always drawn.
- `Title`: The title in 12 px medium text, on one line and cut at the end.
- `Domain`: The domain in 11 px tertiary text, on one line and cut at the end.

## Best practices

### When to use

- Use ChatSource for one source cited in an answer. For a numbered, pinned list of all sources use Source List.

### Do

- Give the card the same number as the citation in the answer text, so a reader finds the source. The card draws the number, and the marker in the text is yours.
- Pass the real address. It opens in a new tab with no referrer and no access to your window, while the default placeholder only calls the click handler.
- Put several sources in a list with an accessible name such as Sources, so a screen reader announces how many there are.
- Give the card a width to truncate in, such as a maximum width in a wrapping row. Without one, a long title makes the card as wide as the line.

### Don't

- Don't put a full URL into the domain. Pass the host, such as wunderui.com, and the page name as the title, and both are cut to one line.
- Don't count on the card to say that it opens a new tab. A screen reader reads only the number, title and domain, so say it in the text next to the list if it matters.

## API reference

### ChatSource

| Prop | Type | Default | Description |
|---|---|---|---|
| domain* | string |  | The host of the source, such as `wunderui.com`, one line, truncated at the end. Not a full address. |
| title* | string |  | The name of the page or document, one line, truncated at the end. |
| active | boolean | false | Marks the source a citation in the answer points at right now. |
| className | string |  | Extra classes for the card, for example `max-w-64` so a long title truncates in a wrapping row. |
| href | string |  | Where the source lives. A real address opens in a new tab with `rel="noreferrer"`; the default `#` does not navigate and only calls `onClick`. |
| icon | ReactNode |  | Replaces the globe, for example a pull-request or file icon. Pass the element, it is sized to 14 px. |
| index | number |  | The number of the citation, drawn in a round badge. Leave it out for a source without a number. |
| onClick | () => void |  | Called when the card is pressed, also when `href` is real. Use it to open the source in a panel or to mark the sentence it backs. |

## Examples

### Content: a short title, a long title, a long host

### Layout: one source, a row that wraps, or a list

### Own icon, active source, button without a link

## In context

### Citations: each sentence names its source

The numbers in the text and on the cards match. Press a source to mark the sentence it backs, and a status line says which one.

### Arrival: the sources show when the answer is complete

Press Ask the question. The sources wait until the reply is complete, then one status line says how many there are, and their space is kept so nothing jumps.

## For AI agents

`get_component("chat-source")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
