For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
FrakmentFrakment

Inline Citation

Attach hoverable source citations to inline text in agent replies.

Next.js streams a route in chunks, so the page shows up before every request finishes.

Wrap a slow part of the page in a Suspense boundary and React sends the fallback first. When the data resolves, the finished HTML streams into the same response and replaces the fallback, with no extra request from the browser. Server Components help here, because their code never ships to the browser.

A loading.tsx file does the same for a whole route segment. It all runs over chunked transfer encoding, so there is nothing extra to set up.

inline-citation-demo.tsx
"use client";

import { Button } from "@/components/ui/button";
import {
  HoverCard,
  HoverCardContent,
  HoverCardTrigger,
} from "@/components/ui/hover-card";

interface Source {
  description: string;
  title: string;
  url: string;
}

const sources = {
  chunked: {
    description: "Send a response as a series of chunks.",
    title: "Transfer-Encoding",
    url: "https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Transfer-Encoding",
  },
  loading: {
    description: "Show an instant loading state for a route segment.",
    title: "loading.js",
    url: "https://nextjs.org/docs/app/api-reference/file-conventions/loading",
  },
  serverComponents: {
    description: "Components that render ahead of time, on the server.",
    title: "Server Components",
    url: "https://react.dev/reference/rsc/server-components",
  },
  streaming: {
    description: "How the App Router streams a route to the browser.",
    title: "Linking and Navigating",
    url: "https://nextjs.org/docs/app/getting-started/linking-and-navigating#streaming",
  },
  suspense: {
    description: "Display a fallback until its children have finished loading.",
    title: "<Suspense>",
    url: "https://react.dev/reference/react/Suspense",
  },
} satisfies Record<string, Source>;

function hostname(url: string) {
  return new URL(url).hostname.replace(/^www\./u, "");
}

function Citation({ source }: { source: Source }) {
  const host = hostname(source.url);

  return (
    <HoverCard closeDelay={100} openDelay={10}>
      <HoverCardTrigger
        as={Button}
        className="h-5 rounded-full px-2 text-xs font-medium"
        size="sm"
        variant="secondary"
      >
        {host}
      </HoverCardTrigger>
      <HoverCardContent className="flex w-64 flex-col gap-1">
        <div className="font-medium">{source.title}</div>
        <p className="text-muted-foreground">{source.description}</p>
        <a
          className="text-muted-foreground text-xs underline-offset-4 hover:underline"
          href={source.url}
          rel="noreferrer"
          target="_blank"
        >
          {host}
          <span className="sr-only"> (opens in a new tab)</span>
        </a>
      </HoverCardContent>
    </HoverCard>
  );
}

export function InlineCitationDemo() {
  return (
    <div className="mx-auto flex max-w-sm flex-col gap-3 py-6 text-sm leading-relaxed">
      <p>
        Next.js streams a route in chunks, so the page shows up before every
        request finishes. <Citation source={sources.streaming} />
      </p>
      <p>
        Wrap a slow part of the page in a Suspense boundary and React sends the
        fallback first. When the data resolves, the finished HTML streams into
        the same response and replaces the fallback, with no extra request from
        the browser. <Citation source={sources.suspense} /> Server Components
        help here, because their code never ships to the browser.
        <Citation source={sources.serverComponents} />
      </p>
      <p>
        A loading.tsx file does the same for a whole route segment.
        <Citation source={sources.loading} /> It all runs over chunked transfer
        encoding, so there is nothing extra to set up.
        <Citation source={sources.chunked} />
      </p>
    </div>
  );
}

Inline Citation is a compact source badge that expands into a HoverCard with the title, description, and a link to the original page. It composes HoverCard and Button, so the badge inherits the button's focus and the card's portal behavior.

Inline Citation is a composition, not a primitive. Install the two primitives it uses, then wire it the same way the demo does.

Installation

Usage

citation.tsx
import { Button } from "@/components/ui/button";
import {
  HoverCard,
  HoverCardContent,
  HoverCardTrigger,
} from "@/components/ui/hover-card";
 
<HoverCard>
  <HoverCardTrigger asChild>
    <Button className="h-5 rounded-full px-2 text-xs font-medium" size="sm" variant="secondary">{host}</Button>
  </HoverCardTrigger>
  <HoverCardContent className="flex w-64 flex-col gap-1">
    <div className="font-medium">{source.title}</div>
    <p className="text-muted-foreground">{source.description}</p>
    <a href={source.url} target="_blank" rel="noreferrer">
      {host}
    </a>
  </HoverCardContent>
</HoverCard>

Anatomy

citation.tsx
<HoverCard>
  <HoverCardTrigger asChild>
    <Button className="h-5 rounded-full px-2 text-xs font-medium" size="sm" variant="secondary">{host}</Button>
  </HoverCardTrigger>
  <HoverCardContent>
    <span>{title}</span>
    <p>{description}</p>
    <a href={url}>{host}</a>
  </HoverCardContent>
</HoverCard>
  • HoverCardTrigger — a compact Button that shows the source hostname.
  • HoverCardContent — a small card with title, description, and a link to the original page.

Formatting the hostname

The badge shows the hostname without www.. Strip it with new URL(url).hostname and a single replace:

tsx
function hostname(url: string) {
  return new URL(url).hostname.replace(/^www\./u, "");
}

Best Practices

  • Always link to the source. A citation without a clickable link is a dead end.
  • Open in a new tab. target="_blank" and rel="noreferrer" so the reader doesn't lose the conversation.
  • Include (opens in a new tab) for screen readers. Use a visually hidden <span className="sr-only">.
  • Keep descriptions short. Two lines at most; the full context lives on the linked page.
  • Do not nest citations. Each claim gets one badge.

Accessibility

  • HoverCardTrigger asChild composes with a focusable Button, so keyboard users can open the preview with Tab and Enter.
  • The description is plain text and read after the title.
  • The link inside HoverCardContent is a real anchor with a visible label and a screen-reader suffix.
  • Do not rely on hover alone; the trigger being a button ensures touch and keyboard users can open it.

Next

  • Chat — full streaming chat surface.
  • Context — context window indicator.
  • Hover Card — rich content on hover.