Inline Citations

Numbered citations in an answer, each opening a preview of its source.

PROGet Inline Citations and 168 other Pro components with pro lifetime — Get Pro

Category
AI Chat
Access
Pro
Source
372 lines · one file
States
5 drawn

The decision inside it

A missing source is shown, never dropped

A marker with nothing behind it is drawn as a dashed "?" that says Source missing. A model citing something it never retrieved is the failure citations exist to catch, so the component makes it visible.

When to use it

Use Inline Citations to render an AI answer that cites sources: [1] or [^id] markers become chips or footnotes with a preview of the source, and the cited sentence lights up. For checking whether each claim is supported, use Citation Verification.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Inline Citations for this.
Install it: npx shadcn@latest add @liro/inline-citations
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/inline-citations.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Pro components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/cited-answer.tsx
import { InlineCitations, type CitationSource } from "@/components/ui/inline-citations";

export function CitedAnswer({ answer, sources }: { answer: string; sources: CitationSource[] }) {
  return <InlineCitations content={answer} sources={sources} showSourceList />;
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
contentstring YesThe answer, with [1] or [^id] markers. Blank lines separate paragraphs.
sourcesCitationSource[] YesWhat the markers point at.
variant"inline" | "footnotes" No"inline" chips in the text, or "footnotes" with superscript numbers. Default inline.
highlightOnHoverboolean NoLight up the sentence a citation supports while it is hovered or focused. Default true.
onSourceClick(source: CitationSource) => void NoCalled when a source is opened from a preview or the list. Without it, sources with a url open in a new tab.
showSourceListboolean NoSource cards under the answer. Default false (true for footnotes).

Dependencies

npm packages

@radix-ui/react-popoverclsxlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-theme

States

All of them are drawn by the component. None is left for you to design.

  • Inline
  • Footnotes
  • Preview open
  • Sentence lit
  • Missing source

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances