Conversation

The Conversation component wraps messages and automatically scrolls to the bottom. Also includes a scroll button that appears when not at the bottom.

Start a conversation

Messages will appear here as the conversation progresses.

Installation

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

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

pnpm dlx jsrepo add @ai/elements/ai-elements/conversation

Usage

Usage with AI SDK

Build a simple conversational UI with Conversation and PromptInput:

Add the following component to your frontend:

+page.svelte

Add the following route to your backend:

api/chat/+server.ts

Features

  • Automatic scrolling to the bottom when new messages are added
  • Smooth scrolling behavior with configurable animation
  • Scroll button that appears when not at the bottom
  • Responsive design with customizable padding and spacing
  • Flexible content layout with consistent message spacing
  • Accessible with proper ARIA roles for screen readers
  • Customizable styling through class prop
  • Support for any number of child message components

Props

Conversation

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the conversation container
initialScrollBehavior'smooth'Scroll behavior for initial scroll to bottom ('auto' | 'smooth')
resizeScrollBehavior'smooth'Scroll behavior when container resizes ('auto' | 'smooth')
childrenSnippet-Child components (typically ConversationContent and ConversationScrollButton)
refHTMLDivElement-Bindable reference to the conversation container element
...restPropsHTMLAttributes<HTMLDivElement>-All other div props are supported

ConversationContent

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the content container
childrenSnippet-Message components to render in the conversation
refHTMLDivElement-Bindable reference to the content container element
...restPropsHTMLAttributes<HTMLDivElement>-All other div props are supported

ConversationEmptyState

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the empty state container
titlestring'No messages yet'Title text to display in the empty state
descriptionstring'Start a conversation to see messages here'Description text to display in the empty state
iconSnippet-Custom icon snippet to display above the title
childrenSnippet-Custom content to replace the default empty state layout
refHTMLDivElement-Bindable reference to the empty state container element
...restPropsHTMLAttributes<HTMLDivElement>-All other div props are supported

ConversationScrollButton

PropTypeDefaultDescription
classstring-Additional CSS classes to apply to the scroll button
onclickMouseEventHandler<HTMLButtonElement>-Click handler for the scroll button
...restPropsButtonProps-All other Button component props are supported