Citation

Pro

The 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.

Largest Contentful Paint marks the moment the main content of a page becomes visible1. A good score is 2.5 seconds or less, measured at the 75th percentile of real page loads2. It is one of the three Core Web Vitals, alongside INP and CLS3.

Try it yourself. This one is live, and its code is right below.

Largest Contentful Paint marks the moment the main content of a page becomes visible1. A good score is 2.5 seconds or less, measured at the 75th percentile of real page loads2. It is one of the three Core Web Vitals, alongside INP and CLS3.

Installation#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Activate your Pro license (once per machine)npx koalaui-cli@latest login <key># Add this component (its dependencies come along)npx koalaui-cli@latest add citation

Usage#

This example is part of Koala UI Pro

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.

A good LCP is 2.5 seconds or less1.

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.

A good LCP is 2.5 seconds or less1.

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.

A good LCP is 2.5 seconds or less1.

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.

This example is part of Koala UI Pro

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), Enter opens the source on show, and Esc closes 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.

Good LCP is 2.5 seconds or less1, INP 200 ms12.

Good LCP is 2.5 seconds or less1, INP 200 ms12.

Good LCP is 2.5 seconds or less1, INP 200 ms12.

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 Reportdeveloper.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.

What counts as a good LCP?

2.5 seconds or less, measured at the 75th percentile of page loads1. Between 2.5 and 4 seconds needs improvement, and anything slower is poor2.

Lab tools give you a single run; the number that counts is the field data from the Chrome UX Report3.

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.

PropTypeDefaultDescription
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.
indexnumber-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.
openboolean-The controlled open state. Pair it with onOpenChange.
defaultOpenbooleanfalseThe 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.
openDelaynumber300Hover and focus intent before the card opens, in ms. Shorter than a plain HoverCard's 700. A tap opens at once.
closeDelaynumber200Delay before the card closes once the pointer or focus leaves, in ms.
childrenReact.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.

PropTypeDefaultDescription
childrenReact.ReactNode-Overrides the label (the index, or the domain and count).
Data attributeDescription
data-slotcitation-trigger. Chat's prose styles skip it, and CitationClaim watches it.
data-stateopen 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 attributeDescription
data-layoutpaged 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.

PropTypeDefaultDescription
href*string-The page. The domain and favicon derive from it.
titlestring-The page title, clamped to two lines.
quotestring-The passage the claim rests on, set off by a rule and clamped to three lines.
descriptionstring-What the page is about (a summary or search snippet), muted and clamped to three lines.
datestring-When the page was published or updated, already formatted (Mar 2024, 2 days ago), after the domain.
faviconstring-Overrides the favicon derived from the domain.
Data attributeDescription
data-positionIn 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.

FAQ#

Because the chip marks a claim, not a link. Three chips in a row at the end of a sentence are noise the reader has to parse; one chip that opens onto three sources says the same thing and keeps the sentence readable.