Citation
A numbered inline marker that names its source, with a hover preview of the page it cites.
c2-citation is the numbered marker an AI answer puts after a claim to say where it comes from, like the inline citations of Perplexity and ChatGPT search. The marker is a link to the source; hovering or focusing it opens a card with the site, the page’s title, the passage quoted and the address, which the pointer can move into and Escape closes.
Import
import '@c2n/components/citation'Usage
Lit renders components to static HTML on the server and hydrates them in the browser Lit's SSR renders components to static HTML in Node, then hydrates them in the browser so they become interactive. Declarative Shadow DOM is a web platform feature that lets you define shadow roots in HTML, without JavaScript.
The source
href is the page cited, source-title its title, snippet the passage the text draws on, site the site’s name (by default the address’s host, without www.) and favicon its icon. index is the number in the marker; the default slot replaces it with your own text, such as the site’s name. The preview slot replaces the whole card.
Only http(s) and relative addresses become a link, and only those (plus data:image/) load as an icon. Sources often come from a model’s output, so a javascript: or other address is dropped: the marker is then a button that only opens its preview.
Opening the card
The card is a c2-hover-card: it opens open-delay milliseconds (300 by default) after the pointer rests on the marker, or at once on keyboard focus, beside the marker at placement (top by default), and flips when there is no room. On touch it does not open, since a tap follows the link. So the card adds a preview; it should not be the only place a source is named — list the sources under the answer too.
Accessibility
A screen reader hears the marker as Source 1: <title> in the page’s language, a link that opens in a new tab by default (target). Its icon is decorative (alt="").