Inline Citation

The Inline Citation component provides a way to display citations inline with text content, similar to academic papers or research documents. It consists of a citation pill that shows detailed source information on hover, making it perfect for AI-generated content that needs to reference sources.

Inline Citation Example

Modern web development has evolved significantly over the past few years. New frameworks like Svelte offer better performance and developer experience compared to traditional approaches.

Installation

pnpm dlx shadcn-svelte@latest add https://svelte-ai-elements.vercel.app/r/inline-citation.json

If you prefer using jsrepo, please install via the command below:

pnpm dlx jsrepo add @ai/elements/ai-elements/inline-citation

Usage

Usage with AI SDK

Build citations for AI-generated content using experimental_useObject from @ai-sdk/svelte.

Add the following component to your frontend:

+page.svelte

Add the following route to your backend:

api/citation/+server.ts

Features

  • Hover interaction to reveal detailed citation information
  • Carousel navigation for multiple citations with prev/next controls
  • Live index tracking showing current slide position (e.g., "1/5")
  • Support for source titles, URLs, and descriptions
  • Optional quote blocks for relevant excerpts
  • Composable architecture for flexible citation formats
  • Accessible design with proper keyboard navigation
  • Seamless integration with AI-generated content
  • Clean visual design that doesn't disrupt reading flow
  • Smart badge display showing source hostname and count

Props

InlineCitation

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the inline citation container
childrenSnippet-Citation content (typically InlineCitationText and InlineCitationCard)
...restPropsHTMLAttributes<HTMLSpanElement>-All other span props are supported

InlineCitationCard

PropTypeDefaultDescription
closeDelaynumber0Delay in milliseconds before closing the hover card
openDelaynumber0Delay in milliseconds before opening the hover card
openboolean-Controls whether the card is open (bindable)
childrenSnippet-Card content (typically InlineCitationCardTrigger and InlineCitationCardBody)

InlineCitationCardTrigger

PropTypeDefaultDescription
sourcesstring[]-Array of source URLs to display in the badge
variant'default' | 'secondary' | 'destructive' | 'outline''secondary'Badge variant style
classstring-Additional CSS classes to apply to the badge
childrenSnippet-Custom badge content (defaults to hostname with count)

InlineCitationCardBody

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the card body
childrenSnippet-Card body content (typically InlineCitationCarousel)

InlineCitationCarousel

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the carousel
optsobject-Embla carousel options
pluginsany[]-Embla carousel plugins
orientation'horizontal' | 'vertical''horizontal'Carousel orientation
childrenSnippet-Carousel content (typically header, content, and navigation)

InlineCitationCarouselHeader

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the carousel header
childrenSnippet-Header content (typically index and navigation buttons)
...restPropsHTMLAttributes<HTMLDivElement>-All other div props are supported

InlineCitationCarouselContent

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the carousel content
childrenSnippet-Carousel items (InlineCitationCarouselItem components)

InlineCitationCarouselItem

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the carousel item
childrenSnippet-Item content (typically InlineCitationSource)

InlineCitationCarouselNext

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the next button
...restPropsHTMLButtonAttributes-All other button props are supported

InlineCitationCarouselPrev

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the previous button
...restPropsHTMLButtonAttributes-All other button props are supported