Skip to Content
✨ Svelte Flow 1.0 is here! Rewritten for Svelte 5 with many new features and improvements.
Reference<SvelteFlow />

<SvelteFlow />

Source on Github 

The <SvelteFlow /> component is the heart of your Svelte Flow application.

<script> import { SvelteFlow } from '@xyflow/svelte'; import '@xyflow/svelte/dist/style.css'; let nodes = $state.raw([ { id: 'a', data: { label: 'node a' }, position: { x: 0, y: 0 } }, { id: 'b', data: { label: 'node b' }, position: { x: 0, y: 100 } } ]); let edges = $state.raw([ { id: 'e1-2', source: 'a', target: 'b' } ]); </script> <SvelteFlow bind:nodes bind:edges fitView />

This component takes a lot of different props, most of which are optional. We’ve tried to document them in groups that make sense to help you find your way.

Common props

These are the props you will most commonly use when working with Svelte Flow.

NameTypeDefault
widthnumber

Sets a fixed width for the flow

heightnumber

Sets a fixed height for the flow

nodesNode[]

An array of nodes to render in a flow.

edgesEdge[]

An array of edges to render in a flow.

nodeTypesNodeTypes

Custom node types to be available in a flow. Svelte Flow matches a node’s type to a component in the nodeTypes object.

edgeTypesEdgeTypes

Custom edge types to be available in a flow. Svelte Flow matches an edge’s type to a component in the edgeTypes object.

colorModeColorMode

Controls color scheme used for styling the flow

'system'
colorModeSSROmit<ColorMode, "system">

Fallback color mode for SSR if colorMode is set to ‘system’

proOptionsProOptions

By default, we render a small attribution in the corner of your flows that links back to the project. You are free to remove this attribution but we ask that you take a quick look at our https://svelteflow.dev/learn/troubleshooting/remove-attribution  removing attribution guide before doing so.

...propsHTMLAttributes<HTMLDivElement>

Viewport props

NameTypeDefault
viewportViewport

Custom viewport to be used instead of internal one

initialViewportViewport

Sets the initial position and zoom of the viewport. If a default viewport is provided but fitView is enabled, the default viewport will be ignored.

{ zoom: 1, position: { x: 0, y: 0 } }
fitViewboolean

If set, initial viewport will show all nodes & edges

fitViewOptionsFitViewOptions<Node>

Options to be used in combination with fitView

minZoomnumber

Minimum zoom level

0.5
maxZoomnumber

Maximum zoom level

2
snapGridSnapGrid

Grid all nodes will snap to

onlyRenderVisibleElementsboolean

You can enable this optimisation to instruct Svelte Flow to only render nodes and edges that would be visible in the viewport. This might improve performance when you have a large number of nodes and edges but also adds an overhead.

false
translateExtentCoordinateExtent

By default the viewport extends infinitely. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right.

[[-∞, -∞], [+∞, +∞]]
preventScrollingboolean

Disabling this prop will allow the user to scroll the page even when their pointer is over the flow.

true
attributionPositionPanelPosition

Set position of the attribution

'bottom-right'

Node props

NameTypeDefault
nodeOriginNodeOrigin

Defines nodes relative position to its coordinates

[0, 0]
nodesDraggableboolean

Controls if all nodes should be draggable

true
nodesConnectableboolean

Controls if all nodes should be connectable to each other

true
nodesFocusableboolean

When true, focus between nodes can be cycled with the Tab key and selected with the Enter key. This option can be overridden by individual nodes by setting their focusable prop.

true
nodeDragThresholdnumber

With a threshold greater than zero you can control the distinction between node drag and click events. If threshold equals 1, you need to drag the node 1 pixel before a drag event is fired.

1
nodeClickDistancenumber

Distance that the mouse can move between mousedown/up that will trigger a click

0
nodeExtentCoordinateExtent

By default the nodes can be placed anywhere. You can use this prop to set a boundary. The first pair of coordinates is the top left boundary and the second pair is the bottom right.

[[-∞, -∞], [+∞, +∞]]
elevateNodesOnSelectboolean

Enabling this option will raise the z-index of nodes when they are selected.

true

Edge props

NameTypeDefault
edgesFocusableboolean

When true, focus between edges can be cycled with the Tab key and selected with the Enter key. This option can be overridden by individual edges by setting their focusable prop.

true
elevateEdgesOnSelectboolean

Enabling this option will raise the z-index of edges when they are selected, or when the connected nodes are selected.

true
defaultMarkerColorstring

Color of edge markers

defaultEdgeOptionsDefaultEdgeOptions

Defaults to be applied to all new edges that are added to the flow. Properties on a new edge will override these defaults if they exist.

Event handlers

General Events

NameTypeDefault
oninit() => void

This handler gets called when the flow is finished initializing

onflowerrorOnError

Ocassionally something may happen that causes Svelte Flow to throw an error. Instead of exploding your application, we log a message to the console and then call this event handler. You might use it for additional logging or to show a message to the user.

ondeleteOnDelete<Node, Edge>

This handler gets called when the user deletes nodes or edges.

onbeforedeleteOnBeforeDelete<Node, Edge>

This handler gets called before the user deletes nodes or edges and provides a way to abort the deletion by returning false.

Node Events

NameTypeDefault
onnodeclickNodeEventWithPointer<MouseEvent | TouchEvent, Node>

This event handler is called when a user clicks on a node.

onnodedragstartNodeTargetEventWithPointer<MouseEvent | TouchEvent, Node>

This event handler is called when a user starts to drag a node.

onnodedragNodeTargetEventWithPointer<MouseEvent | TouchEvent, Node>

This event handler is called when a user drags a node.

onnodedragstopNodeTargetEventWithPointer<MouseEvent | TouchEvent, Node>

This event handler is called when a user stops dragging a node.

onnodepointerenterNodeEventWithPointer<PointerEvent, Node>

This event handler is called when the pointer of a user enters a node.

onnodepointermoveNodeEventWithPointer<PointerEvent, Node>

This event handler is called when the pointer of a user moves over a node.

onnodepointerleaveNodeEventWithPointer<PointerEvent, Node>

This event handler is called when the pointer of a user leaves a node.

onnodecontextmenuNodeEventWithPointer<MouseEvent, Node>

This event handler is called when a user right-clicks on a node.

Edge Events

NameTypeDefault
onedgeclick({ edge, event }: { edge: Edge; event: MouseEvent; }) => void

This event handler is called when a user clicks an edge.

onedgecontextmenu({ edge, event }: { edge: Edge; event: MouseEvent; }) => void

This event handler is called when a user right-clicks an edge.

onedgepointerenter({ edge, event }: { edge: Edge; event: PointerEvent; }) => void

This event handler is called when the pointer of a user enters an edge.

onedgepointerleave({ edge, event }: { edge: Edge; event: PointerEvent; }) => void

This event handler is called when the pointer of a user enters an edge.

onreconnectOnReconnect<Edge>

This event gets fired when after an edge was reconnected

onreconnectstartOnReconnectStart<Edge>

This event gets fired when a user starts to reconnect an edge

onreconnectendOnReconnectEnd<Edge>

This event gets fired when a user stops reconnecting an edge

onbeforereconnectOnBeforeReconnect<Edge>

This handler gets called when an edge is reconnected. You can use it to modify the edge before the update is applied.

Selection Events

NameTypeDefault
onselectionchangedunknown
onselectionclickNodesEventWithPointer<MouseEvent, Node>

This event handler is called when a user clicks the selection box.

onselectioncontextmenuNodesEventWithPointer<MouseEvent, Node>

This event handler is called when a user right-clicks the selection box.

onselectiondragstartOnSelectionDrag<Node>

This event handler gets called when a user starts to drag a selection box.

onselectiondragOnSelectionDrag<Node>

This event handler gets called when a user drags a selection box.

onselectiondragstopOnSelectionDrag<Node>

This event handler gets called when a user stops dragging a selection box.

onselectionstart(event: PointerEvent) => void

This event handler gets called when the user starts to drag a selection box

onselectionend(event: PointerEvent) => void

This event handler gets called when the user finishes dragging a selection box

Pane Events

NameTypeDefault
onpaneclick({ event }: { event: MouseEvent; }) => void

This event handler is called when a user clicks the pane.

onpanecontextmenu({ event }: { event: MouseEvent; }) => void

This event handler is called when a user right-clicks the pane.

onmovestartOnMove

This event handler is called when the user begins to pan or zoom the viewport

onmoveOnMove

This event handler is called when the user pans or zooms the viewport

onmoveendOnMove

This event handler is called when the user stops panning or zooming the viewport

Connection Events

NameTypeDefault
onconnectOnConnect

This event gets fired when a connection successfully completes and an edge is created.

onconnectstartOnConnectStart

When a user starts to drag a connection line, this event gets fired.

onbeforeconnectOnBeforeConnect<Edge>

This handler gets called when a new edge is created. You can use it to modify the newly created edge.

onconnectendOnConnectEnd

When a user stops dragging a connection line, this event gets fired.

isValidConnectionIsValidConnection
clickConnectboolean

Toggles ability to make connections via clicking the handles

onclickconnectstartOnConnectStart

A connection is started by clicking on a handle

onclickconnectendOnConnectEnd

A connection is finished by clicking on a handle

Connection line props

NameTypeDefault
connectionRadiusnumber

The radius around a handle where you drop a connection line to create a new edge.

20
connectionLineComponentComponent<{}, {}, string>

Provide a custom snippet to be used insted of the default connection line

connectionLineTypeConnectionLineType

Choose from the built-in edge types to be used for connections

'default' | ConnectionLineType.Bezier
connectionLineStylestring

Styles to be applied to the connection line

connectionLineContainerStylestring

Styles to be applied to the container of the connection line

Interaction props

NameTypeDefault
elementsSelectableboolean

Controls if all elements should (nodes & edges) be selectable

true
autoPanOnConnectboolean

You can enable this prop to automatically pan the viewport while making a new connection.

true
autoPanOnNodeDragboolean

You can enable this prop to automatically pan the viewport while dragging a node.

true
selectNodesOnDragboolean

Controls if nodes should be automatically selected when being dragged

panOnDragboolean | number[]

Enableing this prop allows users to pan the viewport by clicking and dragging. You can also set this prop to an array of numbers to limit which mouse buttons can activate panning.

true
selectionOnDragboolean

Select multiple elements with a selection box, without pressing down selectionKey.

false
selectionModeSelectionMode

When set to “partial”, when the user creates a selection box by click and dragging nodes that are only partially in the box are still selected.

'full'
panOnScrollboolean

Controls if the viewport should pan by scrolling inside the container Can be limited to a specific direction with panOnScrollMode

false
panOnScrollModePanOnScrollMode

This prop is used to limit the direction of panning when panOnScroll is enabled. The “free” option allows panning in any direction.

"free"
zoomOnScrollboolean

Controls if the viewport should zoom by scrolling inside the container.

true
zoomOnPinchboolean

Controls if the viewport should zoom by pinching on a touch screen

true
zoomOnDoubleClickboolean

Controls if the viewport should zoom by double clicking somewhere on the flow

true
connectionModeConnectionMode

‘strict’ connection mode will only allow you to connect source handles to target handles. ‘loose’ connection mode will allow you to connect handles of any type to one another.

'strict'
paneClickDistancenumber

Distance that the mouse can move between mousedown/up that will trigger a click

0

Keyboard props

NameTypeDefault
deleteKeyKeyDefinition | KeyDefinition[] | null

Pressing down this key deletes all selected nodes & edges.

'Backspace'
selectionKeyKeyDefinition | KeyDefinition[] | null

Pressing down this key you can select multiple elements with a selection box.

'Shift'
multiSelectionKeyKeyDefinition | KeyDefinition[] | null

Pressing down this key you can select multiple elements by clicking.

'Meta' for macOS, "Ctrl" for other systems
zoomActivationKeyKeyDefinition | KeyDefinition[] | null

If a key is set, you can zoom the viewport while that key is held down even if panOnScroll is set to false.

By setting this prop to null you can disable this functionality.

'Meta' for macOS, "Ctrl" for other systems
panActivationKeyKeyDefinition | KeyDefinition[] | null

If a key is set, you can pan the viewport while that key is held down even if panOnScroll is set to false.

By setting this prop to null you can disable this functionality.

'Space'
disableKeyboardA11yboolean

You can use this prop to disable keyboard accessibility features such as selecting nodes or moving selected nodes with the arrow keys.

false

Style props

Applying certain classes to elements rendered inside the canvas will change how interactions are handled. These props let you configure those class names if you need to.

NameTypeDefault
noPanClassstring

If an element in the canvas does not stop mouse events from propagating, clicking and dragging that element will pan the viewport. Adding the "nopan" class prevents this behavior and this prop allows you to change the name of that class.

"nopan"
noDragClassstring

If a node is draggable, clicking and dragging that node will move it around the canvas. Adding the "nodrag" class prevents this behavior and this prop allows you to change the name of that class.

"nodrag"
noWheelClassstring

Typically, scrolling the mouse wheel when the mouse is over the canvas will zoom the viewport. Adding the "nowheel" class to an element n the canvas will prevent this behavior and this prop allows you to change the name of that class.

"nowheel"

Notes

  • The props of this component get exported as SvelteFlowProps
Last updated on