---
title: "Inline Citation"
description: "A source in the sentence that opens on hover."
---

```tsx
import { createMemo } from "solid-js"

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

type Source = {
  url: string
  title: string
  description: string
}

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

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

function Citation(componentProps: { source: Source }) {
  const content = createMemo(() => {
    const { source } = componentProps
    const host = hostname(source.url)
    return (
      <HoverCard delay={10} closeDelay={100}>
        <HoverCardTrigger
          render={(triggerProps) => (
            <Button {...triggerProps} variant="secondary" size="xs">
              {host}
            </Button>
          )}
        />
        <HoverCardContent class="flex w-64 flex-col gap-1">
          <div class="font-medium">{source.title}</div>
          <p class="text-muted-foreground">{source.description}</p>
          <a
            href={source.url}
            target="_blank"
            rel="noreferrer"
            class="text-xs text-muted-foreground underline-offset-4 hover:underline"
          >
            {host}
            <span class="sr-only"> (opens in a new tab)</span>
          </a>
        </HoverCardContent>
      </HoverCard>
    )
  })
  return <>{content()}</>
}

export default function InlineCitationDemo() {
  return (
    <div class="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 source that sits in the sentence it supports. It is a [Hover Card](/docs/components/hover-card/) on a [Button](/docs/components/button/).

To show a list of sources after the reply, use [Sources](/docs/ai-elements/sources/).

## Installation

Inline Citation is built with the [Hover Card](/docs/components/hover-card/) and [Button](/docs/components/button/) components.

<CodeTabs>

<TabsList>
  <TabsTrigger value="cli">Command</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx solidui-cli@latest add hover-card button
```

</TabsContent>

<TabsContent value="manual">

<Steps class="mb-0 pt-2">

<Step>Install the required Solid UI dependencies:</Step>

```bash
npx solidui-cli@latest add hover-card button
```

<Step>Copy and paste the following code into your project.</Step>

```tsx title="components/ui/hover-card.tsx"
type HoverCardProps = ComponentProps<typeof SdkHoverCard>
import { type ComponentProps } from "@solidjs/web"
import {
  HoverCard as SdkHoverCard,
  HoverCardTrigger as SdkHoverCardTrigger,
  HoverCardContent as SdkHoverCardContent
} from "@ui-sdk/solid/hover-card"
import { omit } from "solid-js"

import { cn } from "~/lib/utils"
const HoverCard = (props: HoverCardProps) => <SdkHoverCard {...props} />
type HoverCardTriggerProps = Omit<
  ComponentProps<typeof SdkHoverCardTrigger>,
  "class"
> & {
  class?: string
}
const HoverCardTrigger = (props: HoverCardTriggerProps) => (
  <SdkHoverCardTrigger {...props} />
)
type HoverCardContentProps = Omit<
  ComponentProps<typeof SdkHoverCardContent>,
  "class"
> & {
  class?: string
}
const HoverCardContent = (props: HoverCardContentProps) => {
  const others = omit(props, "class", "children")
  return (
    <>
      <SdkHoverCardContent
        class={cn(
          "w-64 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-ending-style:animate-out data-ending-style:fade-out-0 data-ending-style:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 z-50 origin-(--transform-origin) outline-hidden",
          props.class
        )}
        {...others}
      >
        {props.children}
      </SdkHoverCardContent>
    </>
  )
}
export { HoverCard, HoverCardContent, HoverCardTrigger }
```

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</CodeTabs>

## Usage

```tsx showLineNumbers
<HoverCard openDelay={10} closeDelay={100}>
  <HoverCardTrigger
    render={(triggerProps) => (
      <Button {...triggerProps} variant="secondary" size="xs">
        {hostname}
      </Button>
    )}
  />
  <HoverCardContent class="flex w-64 flex-col gap-1">
    <div class="font-medium">{title}</div>
    <a href={url} target="_blank" rel="noreferrer">
      {hostname}
      <span class="sr-only"> (opens in a new tab)</span>
    </a>
  </HoverCardContent>
</HoverCard>
```

## AI SDK

A `source-url` part is the citation. Set `sendSources: true` on `toUIMessageStreamResponse()`, or write the part yourself.

```ts showLineNumbers title="app/api/chat/route.ts"
writer.write({
  type: "source-url",
  sourceId: "shadcn",
  url: "https://ui.shadcn.com",
  title: "Solid UI"
})
```

```tsx showLineNumbers
const sources = message.parts.filter((part) => part.type === "source-url")
```

`title` is optional. Fall back to the URL's hostname.

## Migrating from AI SDK Elements

If you added Inline Citation from [AI SDK Elements](https://elements.ai-sdk.dev), your project has a `components/ai-elements/inline-citation.tsx` wrapper. Paste this prompt into your coding agent to rebuild it on Hover Card and Button. Every export keeps its name and props, so the code that uses it keeps working.

```txt title="Prompt" prompt
Migrate components/ai-elements/inline-citation.tsx from AI SDK Elements to the Solid UI Hover Card and Button components.

Keep every export, with the same name and props, so the code that imports it keeps working. Only change how each part renders.

1. Install the components: npx solidui-cli@latest add hover-card button
2. Read https://www.solid-ui.com/docs/ai-elements/inline-citation.md and build Inline Citation the same way.
3. Rebuild each part:
   - InlineCitationCard renders a HoverCard with openDelay and closeDelay.
   - InlineCitationCardTrigger renders a HoverCardTrigger with a Button passed through render with variant="secondary" and size="xs" instead of a Badge, so it can take keyboard focus.
   - InlineCitationCardBody renders a HoverCardContent.
   - InlineCitationSource renders the title and a link to the URL that opens in a new tab, with "(opens in a new tab)" in an sr-only span.
   - Keep InlineCitation, InlineCitationText, InlineCitationQuote and the carousel parts as they are.
4. Remove the imports the file no longer uses.
5. Run the type checker and fix any errors.
```
