Message

Composable chat message primitives for Svelte with markdown responses, attachments, branching, and action slots.

What is Svelte? provide some examples

Svelte is a frontend framework used to build fast web applications and user interfaces.

Unlike frameworks like React or Vue.js, Svelte shifts most of the work to the build step instead of doing it in the browser at runtime.

That means:

  • smaller bundle sizes
  • faster websites
  • less boilerplate code
  • simpler reactivity

Simple Example

Counter Example

svelte
<script>	let count = 0;</script>
<button onclick={() => count++}>	Clicked {count} times</button>

When you click the button, the UI updates automatically.

No setState, hooks, or complex state management needed.


Reactive Example

svelte
<script>	let price = 100;	let quantity = 2;
	$: total = price * quantity;</script>
<p>Total: {total}</p>

$: means “rerun this whenever dependencies change”.

If price or quantity changes, total updates automatically.


Conditional Rendering

svelte
<script>	let loggedIn = true;</script>
{#if loggedIn}	<p>Welcome back!</p>{:else}	<p>Please login</p>{/if}

Loop Example

svelte
<script>	let fruits = ["Apple", "Banana", "Mango"];</script>
<ul>	{#each fruits as fruit}		<li>{fruit}</li>	{/each}</ul>

Component Example

Button.svelte

svelte
<script>	export let text = "Click";</script>
<button>{text}</button>

Usage

svelte
<Button text="Submit" />

Why Developers Like Svelte

  • Very readable syntax
  • Less code compared to React
  • Built-in animations/transitions
  • Great performance
  • Excellent developer experience
  • Easy state management

Real Projects Built With Svelte

  • dashboards
  • AI chat apps
  • landing pages
  • blogs
  • animations
  • design systems
  • browser extensions

Since you already work with Svelte, many of your projects like:

  • Svelte AI Elements
  • Svelte Animations
  • Svelte Marketing Blocks

are examples of real-world Svelte ecosystems.

Installation

pnpm dlx shadcn-svelte@latest add http://sveltekit-prerender/r/message.json

Examples

File Attachment Example

Please review these files before we ship the new docs page.

I can review both:

  • Click the image tile to open the centered preview dialog
  • Non-image files stay compact and tooltip-based
  • You can add onRemove when attachments should be dismissible

Branch Message Example

Give me three short ways to introduce the component in docs.

Option 1

Keep it compact and composable. Use Message for layout, MessageContent for a single body, and MessageToolbar only when the message needs controls.

Usage with AI SDK