<SvelteFlow />
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.
| Name | Type | Default | 
|---|---|---|
width | numberSets a fixed width for the flow  | |
height | numberSets a fixed height for the flow  | |
nodes | Node[]An array of nodes to render in a flow.  | |
edges | Edge[]An array of edges to render in a flow.  | |
nodeTypes | NodeTypesCustom node types to be available in a flow. Svelte Flow matches a node’s type to a component in the nodeTypes object.  | |
edgeTypes | EdgeTypesCustom edge types to be available in a flow. Svelte Flow matches an edge’s type to a component in the edgeTypes object.  | |
connectionDragThreshold | numberThe threshold in pixels that the mouse must move before a connection line starts to drag. This is useful to prevent accidental connections when clicking on a handle.  | 1 | 
autoPanSpeed | numberThe speed at which the viewport pans while dragging a node or a selection box.  | 15 | 
autoPanOnNodeFocus | booleanWhen   | true | 
panOnScrollSpeed | numberControls how fast viewport should be panned on scroll.
Use together with   | 0.5 | 
colorMode | ColorModeControls color scheme used for styling the flow  | 'system' | 
colorModeSSR | Omit<ColorMode, "system">Fallback color mode for SSR if colorMode is set to ‘system’  | |
proOptions | ProOptionsBy 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.  | |
ariaLabelConfig | Partial<AriaLabelConfig>Configuration for customizable labels, descriptions, and UI text. Provided keys will override the corresponding defaults. Allows localization, customization of ARIA descriptions, control labels, minimap labels, and other UI strings.  | |
...props | HTMLAttributes<HTMLDivElement> | 
Viewport props
| Name | Type | Default | 
|---|---|---|
viewport | ViewportCustom viewport to be used instead of internal one  | |
initialViewport | ViewportSets 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 } } | 
fitView | booleanIf set, initial viewport will show all nodes & edges  | |
fitViewOptions | FitViewOptionsBase<NodeType>Options to be used in combination with fitView  | |
minZoom | numberMinimum zoom level  | 0.5 | 
maxZoom | numberMaximum zoom level  | 2 | 
snapGrid | SnapGridGrid all nodes will snap to  | |
onlyRenderVisibleElements | booleanYou 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 | 
translateExtent | CoordinateExtentBy 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.  | 
[[-∞, -∞], [+∞, +∞]] | 
preventScrolling | booleanDisabling this prop will allow the user to scroll the page even when their pointer is over the flow.  | true | 
attributionPosition | PanelPositionSet position of the attribution  | 'bottom-right' | 
Node props
| Name | Type | Default | 
|---|---|---|
nodeOrigin | NodeOriginDefines nodes relative position to its coordinates  | [0, 0] | 
nodesDraggable | booleanControls if all nodes should be draggable  | true | 
nodesConnectable | booleanControls if all nodes should be connectable to each other  | true | 
nodesFocusable | booleanWhen   | true | 
nodeDragThreshold | numberWith 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 | 
nodeClickDistance | numberDistance that the mouse can move between mousedown/up that will trigger a click  | 0 | 
nodeExtent | CoordinateExtentBy 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.  | [[-∞, -∞], [+∞, +∞]] | 
elevateNodesOnSelect | booleanEnabling this option will raise the z-index of nodes when they are selected.  | true | 
Edge props
| Name | Type | Default | 
|---|---|---|
edgesFocusable | booleanWhen   | true | 
elevateEdgesOnSelect | booleanEnabling this option will raise the z-index of edges when they are selected, or when the connected nodes are selected.  | true | 
defaultMarkerColor | string | nullColor of edge markers
You can pass   | |
defaultEdgeOptions | DefaultEdgeOptionsDefaults 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
| Name | Type | Default | 
|---|---|---|
oninit | () => voidThis handler gets called when the flow is finished initializing  | |
onflowerror | OnErrorOcassionally 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.  | |
ondelete | OnDelete<Node, Edge>This handler gets called when the user deletes nodes or edges.  | |
onbeforedelete | OnBeforeDelete<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
| Name | Type | Default | 
|---|---|---|
onnodeclick | NodeEventWithPointer<MouseEvent | TouchEvent, Node>This event handler is called when a user clicks on a node.  | |
onnodedragstart | NodeTargetEventWithPointer<MouseEvent | TouchEvent, Node>This event handler is called when a user starts to drag a node.  | |
onnodedrag | NodeTargetEventWithPointer<MouseEvent | TouchEvent, Node>This event handler is called when a user drags a node.  | |
onnodedragstop | NodeTargetEventWithPointer<MouseEvent | TouchEvent, Node>This event handler is called when a user stops dragging a node.  | |
onnodepointerenter | NodeEventWithPointer<PointerEvent, Node>This event handler is called when the pointer of a user enters a node.  | |
onnodepointermove | NodeEventWithPointer<PointerEvent, Node>This event handler is called when the pointer of a user moves over a node.  | |
onnodepointerleave | NodeEventWithPointer<PointerEvent, Node>This event handler is called when the pointer of a user leaves a node.  | |
onnodecontextmenu | NodeEventWithPointer<MouseEvent, Node>This event handler is called when a user right-clicks on a node.  | 
Edge Events
| Name | Type | Default | 
|---|---|---|
onedgeclick | ({ edge, event }: { edge: Edge; event: MouseEvent; }) => voidThis event handler is called when a user clicks an edge.  | |
onedgecontextmenu | ({ edge, event }: { edge: Edge; event: MouseEvent; }) => voidThis event handler is called when a user right-clicks an edge.  | |
onedgepointerenter | ({ edge, event }: { edge: Edge; event: PointerEvent; }) => voidThis event handler is called when the pointer of a user enters an edge.  | |
onedgepointerleave | ({ edge, event }: { edge: Edge; event: PointerEvent; }) => voidThis event handler is called when the pointer of a user enters an edge.  | |
onreconnect | OnReconnect<Edge>This event gets fired when after an edge was reconnected  | |
onreconnectstart | OnReconnectStart<Edge>This event gets fired when a user starts to reconnect an edge  | |
onreconnectend | OnReconnectEnd<Edge>This event gets fired when a user stops reconnecting an edge  | |
onbeforereconnect | OnBeforeReconnect<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
| Name | Type | Default | 
|---|---|---|
onselectionchanged | unknown | |
onselectionclick | NodesEventWithPointer<MouseEvent, Node>This event handler is called when a user clicks the selection box.  | |
onselectioncontextmenu | NodesEventWithPointer<MouseEvent, Node>This event handler is called when a user right-clicks the selection box.  | |
onselectiondragstart | OnSelectionDrag<Node>This event handler gets called when a user starts to drag a selection box.  | |
onselectiondrag | OnSelectionDrag<Node>This event handler gets called when a user drags a selection box.  | |
onselectiondragstop | OnSelectionDrag<Node>This event handler gets called when a user stops dragging a selection box.  | |
onselectionstart | (event: PointerEvent) => voidThis event handler gets called when the user starts to drag a selection box  | |
onselectionend | (event: PointerEvent) => voidThis event handler gets called when the user finishes dragging a selection box  | 
Pane Events
| Name | Type | Default | 
|---|---|---|
onpaneclick | ({ event }: { event: MouseEvent; }) => voidThis event handler is called when a user clicks the pane.  | |
onpanecontextmenu | ({ event }: { event: MouseEvent; }) => voidThis event handler is called when a user right-clicks the pane.  | |
onmovestart | OnMoveThis event handler is called when the user begins to pan or zoom the viewport  | |
onmove | OnMoveThis event handler is called when the user pans or zooms the viewport  | |
onmoveend | OnMoveThis event handler is called when the user stops panning or zooming the viewport  | 
Connection Events
| Name | Type | Default | 
|---|---|---|
onconnect | OnConnectThis event gets fired when a connection successfully completes and an edge is created.  | |
onconnectstart | OnConnectStartWhen a user starts to drag a connection line, this event gets fired.  | |
onbeforeconnect | OnBeforeConnect<Edge>This handler gets called when a new edge is created. You can use it to modify the newly created edge.  | |
onconnectend | OnConnectEndWhen a user stops dragging a connection line, this event gets fired.  | |
isValidConnection | IsValidConnection | |
clickConnect | booleanToggles ability to make connections via clicking the handles  | |
onclickconnectstart | OnConnectStartA connection is started by clicking on a handle  | |
onclickconnectend | OnConnectEndA connection is finished by clicking on a handle  | 
Connection line props
| Name | Type | Default | 
|---|---|---|
connectionRadius | numberThe radius around a handle where you drop a connection line to create a new edge.  | 20 | 
connectionLineComponent | Component<{}, {}, string>Provide a custom snippet to be used insted of the default connection line  | |
connectionLineType | ConnectionLineTypeChoose from the built-in edge types to be used for connections  | 'default' | ConnectionLineType.Bezier | 
connectionLineStyle | stringStyles to be applied to the connection line  | |
connectionLineContainerStyle | stringStyles to be applied to the container of the connection line  | 
Interaction props
| Name | Type | Default | 
|---|---|---|
elementsSelectable | booleanControls if all elements should (nodes & edges) be selectable  | true | 
autoPanOnConnect | booleanYou can enable this prop to automatically pan the viewport while making a new connection.  | true | 
autoPanOnNodeDrag | booleanYou can enable this prop to automatically pan the viewport while dragging a node.  | true | 
selectNodesOnDrag | booleanControls if nodes should be automatically selected when being dragged  | |
panOnDrag | boolean | 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 | 
selectionOnDrag | booleanSelect multiple elements with a selection box, without pressing down selectionKey.  | false | 
selectionMode | SelectionModeWhen 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' | 
panOnScroll | booleanControls if the viewport should pan by scrolling inside the container Can be limited to a specific direction with panOnScrollMode  | false | 
panOnScrollMode | PanOnScrollModeThis prop is used to limit the direction of panning when panOnScroll is enabled. The “free” option allows panning in any direction.  | "free" | 
zoomOnScroll | booleanControls if the viewport should zoom by scrolling inside the container.  | true | 
zoomOnPinch | booleanControls if the viewport should zoom by pinching on a touch screen  | true | 
zoomOnDoubleClick | booleanControls if the viewport should zoom by double clicking somewhere on the flow  | true | 
connectionMode | ConnectionMode‘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' | 
paneClickDistance | numberDistance that the mouse can move between mousedown/up that will trigger a click  | 0 | 
Keyboard props
| Name | Type | Default | 
|---|---|---|
deleteKey | KeyDefinition | KeyDefinition[] | nullPressing down this key deletes all selected nodes & edges.  | 'Backspace' | 
selectionKey | KeyDefinition | KeyDefinition[] | nullPressing down this key you can select multiple elements with a selection box.  | 'Shift' | 
multiSelectionKey | KeyDefinition | KeyDefinition[] | nullPressing down this key you can select multiple elements by clicking.  | 'Meta' for macOS, "Ctrl" for other systems | 
zoomActivationKey | KeyDefinition | KeyDefinition[] | nullIf 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 | 
panActivationKey | KeyDefinition | KeyDefinition[] | nullIf 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' | 
disableKeyboardA11y | booleanYou 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.
Notes
- The props of this component get exported as 
SvelteFlowProps