Citation
ProThe mark an answer leaves where a claim came from: a chip in the running text that previews its sources on hover, focus or tap, and goes to them on click. One chip per claim, however many sources back it.
Try it yourself. This one is live, and its code is right below.
Installation#
Usage#
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
Anatomy#
Most of the time <Citation sources={…} /> is all you write: it renders the chip and the card from the data. Compose the parts when the chip needs its own label or the card its own content, and wrap the claim when you want it to light up.
import {
CitationClaim,
Citation,
CitationTrigger,
CitationContent,
CitationSource,
} from "@/components/ui/citation"
<CitationClaim>
…the claim…
<Citation sources={sources}>
<CitationTrigger />
<CitationContent>
<CitationSource />
</CitationContent>
</Citation>
</CitationClaim>The card#
Each source reads top to bottom: the favicon, domain and date as a quiet eyebrow, the page title, then the passage the claim rests on. Pass quote for the cited words, set off by a hairline rule, and description for what the page is about; either is clamped to three lines. The whole row is one link, and the title underlines under the pointer.
Several sources#
When more than one source backs a claim, the card shows one at a time with a 1/N pager in its top corner, and stays open while you step. The next source slides in from the side you stepped toward; the card is as tall as its tallest source, so nothing jumps, and the chip's link follows the source on show. Paging is the default because the card keeps one size and each source gets room for its quote. A stack of three rows would cover the answer it is citing.
layout="list" stacks every source as its own row instead, for short sources a reader should compare side by side. Each row is a link with its hover fill set 8px into the card on the Popover's inset rung, so the corners stay concentric.
Highlighting the claim#
Wrap the words a citation backs in CitationClaim, with the chip inside it. While the chip is hovered the claim takes a faint wash, and while it is focused or open the wash deepens, so the reader sees which sentence the card is talking about. It is a :has() rule on the claim, so it needs no state or ids, and it stays neutral in every theme. Hover the chips in the demo at the top of the page.
The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.
Have a license? Unlock it here
Keyboard and touch#
A plain hover card works for a mouse only. The citation also opens for the keyboard and for touch, and every way in has a way out (WCAG 1.4.13).
- Mouse: hovering the chip opens the card after
openDelay; the card stays open while the pointer is on it; clicking the chip follows the link. - Keyboard: focusing the chip opens the card. Focus stays on the chip:
←/→step through several sources (announced to screen readers),Enteropens the source on show, andEsccloses the card. - Touch: the first tap opens the card instead of leaving the page. Tap a source in the card, or the chip again, to open it; tap anywhere else to close.
In running text#
The chip sizes itself to the prose around it (0.8em, never under the xs step), sits on the text's baseline and never splits across lines, and its padding never grows the line box. Numbers are tabular. On a mouse the chip keeps its own size, because a 40px target would reach into the lines above and below; on touch its target grows to 44px.
Source chips#
variant="source" trades the counter for the favicon and the domain, with +N when more than one source backs the claim: the answer-engine register, where saying where without a hover is worth the width in the line. The counter stays the default because it reads quietest in dense prose.
Interaction to Next Paint reports the slowest interaction a visitor had on the page, not the first oneweb.dev. Field data for it comes from the Chrome UX Report
developer.chrome.com+2.
In a chat#
Drop the chips straight into a Chat turn. The chip carries a data-slot, so the turn's prose styles leave it alone: markdown links get the underline, the chip keeps its own look.
API reference#
Citation
The root: the sources, the open state and the source on show, which every part reads. With no children it renders the chip and the card from sources. Forwards Radix HoverCard.Root props.
| Prop | Type | Default | Description |
|---|---|---|---|
| sources* | CitationSourceData[] | - | { href, title?, description?, quote?, date?, favicon? } per source. The chip links to the source the card is showing, the first one while it is closed. |
| index | number | - | The footnote number the number chip shows. Omitted, it shows the source count. |
| variant | "number" | "source" | "number" | number is a footnote counter; source shows the favicon, the domain and +N. |
| layout | "paged" | "list" | "paged" | How the card shows several sources: one at a time with a 1/N pager, or stacked as rows. A single source looks the same either way. |
| open | boolean | - | The controlled open state. Pair it with onOpenChange. |
| defaultOpen | boolean | false | The open state on mount, uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when hover, focus, a tap, Escape or a tap outside opens or closes the card. |
| openDelay | number | 300 | Hover and focus intent before the card opens, in ms. Shorter than a plain HoverCard's 700. A tap opens at once. |
| closeDelay | number | 200 | Delay before the card closes once the pointer or focus leaves, in ms. |
| children | React.ReactNode | - | Compose the chip and card yourself with CitationTrigger and CitationContent. |
CitationTrigger
The chip: a pill on a real link, opened in a new tab. A mouse click follows it; the first tap on touch opens the card instead. Its accessible name lists every source. Forwards native <a> props except href.
| Prop | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | - | Overrides the label (the index, or the domain and count). |
| Data attribute | Description |
|---|---|
| data-slot | citation-trigger. Chat's prose styles skip it, and CitationClaim watches it. |
| data-state | open while the card is open: the chip inverts to read as active. |
CitationContent
The preview card, growing out of the chip. With no children it shows the sources (paged or stacked, per layout); children replace them with your own CitationSource rows, stacked. Forwards HoverCardContent props (side, align, density).
| Data attribute | Description |
|---|---|
| data-layout | paged when the pager is showing, list otherwise. |
CitationSource
One source: favicon, domain and date as a quiet eyebrow, the title, the quoted passage, the summary. The whole row is a link. Forwards native <a> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| href* | string | - | The page. The domain and favicon derive from it. |
| title | string | - | The page title, clamped to two lines. |
| quote | string | - | The passage the claim rests on, set off by a rule and clamped to three lines. |
| description | string | - | What the page is about (a summary or search snippet), muted and clamped to three lines. |
| date | string | - | When the page was published or updated, already formatted (Mar 2024, 2 days ago), after the domain. |
| favicon | string | - | Overrides the favicon derived from the domain. |
| Data attribute | Description |
|---|---|
| data-position | In the paged card: current, or before / after for the sources off to either side (inert). |
CitationClaim
Optional. Wraps the words a citation backs; while a chip inside it is hovered, focused or open, the claim takes a soft neutral wash. Pure CSS, no state. Forwards native <span> props.