To use Svelte in Astro, run npx astro add svelte, import a .svelte file into any .astro page, and add a client:* directive if it needs to be interactive. Vue works the same way with npx astro add vue. Both can live in the same project, even on the same page, because Astro renders each one as an independent island.
This guide covers setup, props, slots, client directives, sharing state between a Svelte island and a Vue island, and the mistakes that trip people up in Astro 7.
Key Takeaways
npx astro add svelteandnpx astro add vueinstall the renderer and updateastro.config.mjsfor you.- Without a
client:*directive, a Svelte or Vue component renders to static HTML and ships zero JavaScript.- Props must be serializable when the component hydrates: strings, numbers, arrays, plain objects, dates. Functions are not.
- Islands don’t share a framework context, so share state with a small store such as Nano Stores.
- Mixing frameworks is supported, but each one adds its own runtime to pages that use it.
Why use Svelte or Vue in Astro at all
Astro components (.astro files) render on the server and send HTML. They are the right default for layouts, cards, headers and anything that doesn’t change after the page loads. When part of the page needs real client-side state, such as a filterable list, a multi-step form or a cart drawer, you reach for a UI framework.
Svelte is a common choice for Astro islands because it compiles to small, framework-light output. Vue is a common choice when a team already has Vue components or prefers single-file components with <script setup>. Astro doesn’t force a pick. You can write most of the site in .astro, then drop in a Svelte widget here and a Vue widget there.
If you are still deciding between a framework island and a plain <script> tag, the island or script decision guide walks through that choice.
Install the Svelte and Vue integrations
Run the official astro add command for each framework you want:
npx astro add svelte
npx astro add vue
Each command installs the integration package plus the framework itself, then edits your config. The result looks like this:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import svelte from '@astrojs/svelte';
import vue from '@astrojs/vue';
export default defineConfig({
integrations: [svelte(), vue()],
});
Svelte also needs a small config file so editor tooling and the compiler agree on preprocessing. astro add svelte creates it:
// svelte.config.js
import { vitePreprocess } from '@astrojs/svelte';
export default {
preprocess: vitePreprocess(),
};
The current @astrojs/svelte integration targets Svelte 5, so write components with runes ($props(), $state()). For Vue, install the official Vue extension in your editor so .vue files get type checking. The Astro framework components docs list every supported renderer.
Write a Svelte component and use it in Astro
Here is a small counter written in Svelte 5:
<!-- src/components/Counter.svelte -->
<script lang="ts">
let { start = 0, label = 'Count' }: { start?: number; label?: string } = $props();
let count = $state(start);
</script>
<button type="button" onclick={() => count++}>
{label}: {count}
</button>
Import it into a page or another Astro component like any other module:
---
// src/pages/index.astro
import Counter from '../components/Counter.svelte';
---
<h1>Svelte in Astro</h1>
<!-- Static HTML only, no JavaScript sent -->
<Counter start={5} label="Static" />
<!-- Hydrated island: interactive in the browser -->
<Counter client:load start={5} label="Interactive" />
The first <Counter> renders the button markup on the server and stops there. Clicking it does nothing, because no JavaScript was sent. The second one gets client:load, so Astro sends the Svelte runtime plus the component and hydrates it as soon as the page loads.
Write a Vue component and use it in Astro
The same idea in Vue, using <script setup>:
<!-- src/components/Toggle.vue -->
<script setup lang="ts">
import { ref } from 'vue';
const props = defineProps<{ title: string; open?: boolean }>();
const isOpen = ref(props.open ?? false);
</script>
<template>
<section>
<button type="button" :aria-expanded="isOpen" @click="isOpen = !isOpen">
{{ title }}
</button>
<div v-show="isOpen">
<slot />
</div>
</section>
</template>
Use it from Astro and pass children as the default slot:
---
// src/pages/faq.astro
import Toggle from '../components/Toggle.vue';
---
<Toggle client:visible title="Do I need Vue for the whole site?">
<p>No. Only this component ships Vue's runtime.</p>
</Toggle>
client:visible waits until the component scrolls into view before loading any JavaScript, which suits content further down the page. Vue’s named slots work too: put slot="footer" on an element in Astro and render it with <slot name="footer" /> inside the Vue component.
In Svelte 5, the default content you pass from Astro arrives as the children snippet, so render it with {@render children?.()} after reading children from $props().
Choosing a client directive for each island
Directives behave identically for Svelte, Vue, React or any other renderer. Pick the one that matches when the user actually needs the component:
| Directive | When JavaScript loads | Good for |
|---|---|---|
| none | never | display-only components |
client:load |
immediately on page load | above-the-fold controls, nav menus |
client:idle |
when the browser is idle | chat widgets, low-priority UI |
client:visible |
when the element enters the viewport | carousels, comments, footer forms |
client:media="(max-width: 768px)" |
when the media query matches | mobile-only drawers |
client:only="svelte" |
in the browser only, no server render | components that need window |
With client:only, tell Astro which renderer to use, because it skips the server render that normally reveals it: client:only="svelte" or client:only="vue". The client directive chooser has a longer decision tree.
Passing props from Astro to Svelte and Vue
Props flow in from the Astro side just like HTML attributes. For server-only rendering you can pass anything. For hydrated islands, Astro serializes props into the HTML so the browser can rebuild them, which sets a few limits:
- Supported: strings, numbers, booleans,
null, arrays, plain objects,Date,Map,Set,URL,RegExp,BigInt, typed arrays. - Not supported: functions and class instances. A click handler from an Astro page can’t cross into the island.
Fetch data in the Astro frontmatter and pass the result down:
---
// src/pages/products.astro
import ProductFilter from '../components/ProductFilter.svelte';
const products = [
{ id: 'a1', name: 'Desk lamp', price: 49, tags: ['lighting'] },
{ id: 'b2', name: 'Monitor arm', price: 89, tags: ['desk'] },
];
---
<ProductFilter client:idle products={products} />
Keep island props small. Everything you pass is embedded in the page, so passing a 2 MB JSON blob makes the HTML 2 MB larger. Filter on the server first and send only what the island needs.
Sharing state between Svelte and Vue islands
Each island hydrates on its own with its own framework root. A Svelte store doesn’t reach a Vue component, and a Vue provide doesn’t reach a sibling island. The usual answer is a framework-agnostic store. Nano Stores is the library the Astro docs use for this:
npm install nanostores @nanostores/vue
// src/stores/cart.ts
import { atom } from 'nanostores';
export const cartCount = atom(0);
Svelte can subscribe to a Nano Store directly with the $ prefix, since it follows the Svelte store contract:
<!-- src/components/AddToCart.svelte -->
<script lang="ts">
import { cartCount } from '../stores/cart';
</script>
<button type="button" onclick={() => cartCount.set($cartCount + 1)}>
Add to cart ({$cartCount})
</button>
Vue uses the useStore helper:
<!-- src/components/CartBadge.vue -->
<script setup lang="ts">
import { useStore } from '@nanostores/vue';
import { cartCount } from '../stores/cart';
const count = useStore(cartCount);
</script>
<template>
<span aria-live="polite">Cart: {{ count }}</span>
</template>
Put both on the page with client:* directives and they stay in sync, because both import the same module instance in the browser. For a deeper look at this pattern, see the Astro islands architecture guide.
Mixing frameworks: what it costs
Astro will happily render a Svelte header, a Vue form and a React chart on one page. The trade-off is weight. Every framework you hydrate on a page adds its runtime to that page’s JavaScript. Svelte’s runtime is small, Vue’s is larger, and running both means the visitor downloads both.
A sensible rule for real projects:
- Default to
.astrocomponents for anything that doesn’t need state. - Pick one framework for islands and stick with it across the site.
- Bring in a second framework only to reuse existing components, such as a Vue widget from an older app.
- Check the build output with
astro buildand look at the client chunks per page.
Many production-ready Astro themes ship with no UI framework at all and use small <script> tags for menus and toggles. That keeps every page fast and leaves you free to add Svelte or Vue only where a feature needs it.
Common errors and fixes
A few problems come up repeatedly when adding Svelte or Vue to an Astro project:
- The component renders but nothing happens on click. You forgot a
client:*directive. Without one, Astro sends HTML only. window is not definedduring build. The component touches browser APIs at the top level. Move that code intoonMount(Svelte) oronMounted(Vue), or useclient:only.- No renderer found for a
client:onlycomponent. Pass the framework name:client:only="vue". The no matching renderer fix covers the full error. - A function prop is undefined in the browser. Functions can’t be serialized. Move the handler inside the island.
If you’d like to see how a full project is organized before adding islands, the Astro project structure docs show where components, layouts and pages live.
FAQ
Can I use Svelte and Vue in the same Astro project?
Yes. Install both integrations with npx astro add svelte and npx astro add vue, and import .svelte and .vue files wherever you need them. Each component hydrates as its own island, so they don’t conflict, though each framework adds its own runtime to pages that hydrate it.
Does Astro support Svelte 5?
Yes. The current @astrojs/svelte integration is built for Svelte 5, so components use runes such as $props() and $state(). Older Svelte 4 syntax like export let belongs to older integration versions.
Do Svelte components in Astro ship JavaScript by default?
No. A Svelte or Vue component without a client:* directive renders to plain HTML on the server and sends no JavaScript. Add client:load, client:idle, client:visible or another directive to make it interactive.
How do I share state between a Svelte and a Vue component in Astro?
Use a framework-agnostic store such as Nano Stores. Define the store in a plain TypeScript module, subscribe with $store in Svelte and useStore() from @nanostores/vue in Vue. Both islands import the same module in the browser, so updates in one appear in the other.
Is Svelte or Vue better for Astro islands?
Both work well. Svelte tends to produce smaller client bundles, which suits a few interactive widgets on a content site. Vue is a good fit if you already have Vue components or a team that knows it. Pick one for consistency rather than mixing them by default.