Inline citation

Markers inside an answer that show where a claim came from: numbers, superscripts, a site chip, the quoted passage itself, or notes in the margin of a long report.

Loading preview…

Install

  1. 1

    Run this command in your Tailwind CSS project. It adds components/ai/inline-citation-pill.tsx and installs its dependencies.

    $ npx shadcn@latest add https://gradientdeck.com/ai-components/r/inline-citation-pill.json

Add citations and source cards to an AI answer →

Usage & API

Example

inline-citation-pill.tsx
import { CitedAnswer } from "@/components/ai/inline-citation-pill"

<CitedAnswer
  parts={[]}
  sources={[]}
/>

Props CitedAnswer

PropType & descriptionRequired
partsAnswerPart[]Required
sourcesCitationSource[]Required
defaultOpennumberOpen the card for this citation (0-based, counting citations only) on mount.Optional

Dependencies

  • React
  • Tailwind CSS
  • motion
Implementation notes

Pill exports CitedAnswer with parts, sources, and defaultOpen. Each citation is a round button, at least 18px tall, showing the cite number. The accessible name is Source {n}: {site}. The card is a tooltip, at most 296px wide, placed from the marker's rectangle. It shows a letter favicon, the site, the domain, a two-line title, and a three-line snippet. Moving the pointer onto the card cancels the close timer, which is 140ms. There is no footnote list under the paragraph. The card opened by defaultOpen is dismissed on the first pointer enter, so it does not stick to the demo.

Choosing a layout

Use a pill or a superscript when every citation is one source and a short card is enough. The superscript also prints a numbered list under the paragraph, and the row for the open source is emphasised, so it suits an answer that should keep a visible bibliography. Use a source chip when one clause rests on two or three domains and you want the domain in the marker, not a bare number. Use a quoted span when the reader needs the passage, and a warning when the source only backs part of the sentence. Use margin notes for a report the person will read and pin, not for a one-paragraph chat reply.

Do not use these to list every page the model opened. A chip that says reuters.com is a citation. A button that says 12 sources, a carousel, or a side panel is Sources list. A card for a URL the person pasted, or a hover card on an ordinary link, is Link preview. Keep the marker next to the claim. If you only have a list of URLs and no place to attach them in the prose, you do not have an inline citation yet.

Are the citation numbers zero-based?

No. On the pill and the superscript, cite is 1-based: the button shows cite and the card reads sources[cite - 1]. On margin notes, note is 0-based: the first note is notes[0], and the marker prints note + 1. On the source chip, the numbers inside sources are indexes into the sources array, also 0-based, and the chip shows a domain rather than those indexes. On the quoted span, claim.source is a 0-based index too. defaultOpen, where it exists, counts markers in reading order, starting at 0, not the cite value.

How does a quoted span say the source only partly agrees?

Set support to partial and pass note. The claim underline turns amber, and the accessible name includes partly supported by the site. The card adds a line that starts Partly supported and then the note. If showSummary is left at its default, true, the footer counts how many claims are partial and a button moves focus to the first one, then pins it. match is separate: those phrases are wrapped in mark inside passage, whether support is full or partial. Clicking the claim pins the card so the reader can follow Open source.