Quick Start
This page will take you from zero to a working Svelte Flow app in a few minutes. From there, you can take a deeper look at what Svelte Flow is all about, check out the examples, or dive into the API docs. If you want to get up and running as soon as possible, you’re in the right place!
Installation
To install Svelte Flow in your existing Svelte project, run the following command:
npm install @xyflow/sveltePlay online
You can try Svelte Flow without setting anything up locally by checking out the starter projects we have on CodeSandbox :
Templates
If you want to get started right away, you can use a template.
Svelte Flow Vite template
We have a ready-to-use Vite template that you can use to get up and running in no time.
npx degit xyflow/vite-svelte-flow-template app-nameSvelteKit template
Alternatively, you can spin up a new Svelte with SvelteKit and Vite templates.
npx sv create my-svelte-flow-appNext, cd into your project directory and install the Svelte Flow package:
npm install @xyflow/svelteUsage
The @xyflow/svelte package exports the <SvelteFlow /> component, which is the
entrypoint for your flow. Importing the default styles and defining a handful of nodes and
edges are all we need to get started!
There are a few things to pay attention to here:
- You must import the Svelte Flow stylesheet.
-
<SvelteFlow />inherits the size of its parent. Wrap it in an element with dimensions. - Use
$state.rawinstead of deeply reactive state for thenodesandedgesfor performance reasons .
<script>
import { SvelteFlow } from '@xyflow/svelte';
import '@xyflow/svelte/dist/style.css';
let nodes = $state.raw([
{ id: '1', position: { x: 0, y: 0 }, data: { label: '1' } },
{ id: '2', position: { x: 0, y: 100 }, data: { label: '2' } },
]);
let edges = $state.raw([
{ id: 'e1-2', source: '1', target: '2' },
]);
</script>
<div style:width="100vw" style:height="100vh">
<SvelteFlow bind:nodes bind:edges fitView colorMode="system">
<Controls />
<MiniMap />
<Background variant={BackgroundVariant.Dots} gap={12} size={1} />
</SvelteFlow>
</div>Result
Et voila. You’ve already created your first interactive flow!