Skip to Content
React Flow 13 is here! Read the announcement →

Theming

React Flow has been built with deep customization in mind. Many of our users fully transform the look and feel of React Flow to match their own brand or design system. This guide will introduce you to the different ways you can customize React Flow’s appearance.

Default styles

React Flow’s default styles are enough to get going with the built-in nodes. They provide some sensible defaults for styles like padding, border radius, and animated edges. You can see what they look like below:

import { useCallback } from 'react'; import { ReactFlow, Background, Controls, MiniMap, useNodesState, useEdgesState, addEdge, Position, } from '@xyflow/react'; import './index.css'; const nodeDefaults = { sourcePosition: Position.Right, targetPosition: Position.Left, }; const initialNodes = [ { id: '1', position: { x: 0, y: 150 }, data: { label: 'default style 1' }, ...nodeDefaults, }, { id: '2', position: { x: 250, y: 0 }, data: { label: 'default style 2' }, ...nodeDefaults, }, { id: '3', position: { x: 250, y: 150 }, data: { label: 'default style 3' }, ...nodeDefaults, }, { id: '4', position: { x: 250, y: 300 }, data: { label: 'default style 4' }, ...nodeDefaults, }, ]; const initialEdges = [ { id: 'e1-2', source: '1', target: '2', animated: true, }, { id: 'e1-3', source: '1', target: '3', }, { id: 'e1-4', source: '1', target: '4', }, ]; const Flow = () => { const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); const onConnect = useCallback( (params) => setEdges((els) => addEdge(params, els)), [], ); return ( <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} fitView > <Background /> <Controls /> <MiniMap /> </ReactFlow> ); }; export default Flow;

You’ll typically load these default styles by importing them in your App.jsx file or other entry point:

import '@xyflow/react/style.css';

The shorter @xyflow/react/style.css import is available in React Flow 13. The previous @xyflow/react/dist/style.css path is still supported.

Without dipping into custom nodes and edges, there are three ways you can style React Flow’s basic look:

  • Passing inline styles through style props
  • Overriding the built-in classes with custom CSS
  • Overriding the CSS variables React Flow uses

Using our theme

For xyflow’s themed appearance, import xy-theme.css in place of style.css:

import '@xyflow/react/xy-theme.css';

This stylesheet builds on base.css and includes the styles needed for React Flow to work, so you don’t need a separate base-style import. It adds themed nodes, handles, and controls, with support for light and dark mode. You can customize it with CSS variables and class overrides as described below.

Layered CSS

Since React Flow 13, the library styles are in a CSS layer named xyflow. Declare your layer order before importing styles to control their precedence:

@layer reset, xyflow, app; @import '@xyflow/react/style.css';

For normal declarations, styles in app take precedence over xyflow, while reset has lower priority. Styles outside any layer take precedence over layered styles. Read more about CSS layers on MDN .

Built in dark and light mode

React Flow automatically follows your site’s color mode when an ancestor has data-theme="dark", data-theme="light", or a dark or light class. Otherwise, it follows the user’s operating-system color scheme.

To force a specific mode regardless of your site’s theme, use the forceColorMode prop with 'light' or 'dark':

import ReactFlow from '@xyflow/react'; export default function Flow() { return <ReactFlow forceColorMode="dark" nodes={[]} edges={[]} />; }

You can use light-dark() in your own CSS to follow the same color scheme:

.react-flow__node { background: light-dark(white, #777); color: light-dark(#111, white); }

Customizing with style props

The easiest way to start customizing the look and feel of your flows is to use the style prop found on many of React Flow’s components to inline your own CSS.

import ReactFlow from '@xyflow/react' const styles = { background: 'red', width: '100%', height: 300, }; export default function Flow() { return <ReactFlow style={styles} nodes={[...]} edges={[...]} /> }

CSS variables

If you don’t want to replace the default styles entirely but just want to tweak the overall look and feel, you can override some of the CSS variables we use throughout the library. For an example of how to use these CSS variables, check out our Feature Overview example.

The following table lists the defaults when importing style.css, including the shared base styles. In light-dark(light, dark) values, the first color applies in light mode and the second in dark mode, according to the flow’s CSS color-scheme. CanvasText is the browser’s system text color.

Variable nameDefault
--xy-edge-stroke-defaultlight-dark(#b1b1b7, #3e3e3e)
--xy-edge-stroke-width-default1
--xy-edge-stroke-selected-defaultlight-dark(#555, #727272)
--xy-connectionline-stroke-default#b1b1b7
--xy-connectionline-stroke-width-default1
--xy-attribution-background-color-defaultlight-dark(rgba(255, 255, 255, 0.5), rgba(150, 150, 150, 0.25))
--xy-minimap-background-color-defaultlight-dark(#fff, #141414)
--xy-minimap-mask-background-color-defaultlight-dark(rgba(240, 240, 240, 0.6), rgba(60, 60, 60, 0.6))
--xy-minimap-mask-stroke-color-defaulttransparent
--xy-minimap-mask-stroke-width-default1
--xy-minimap-node-background-color-defaultlight-dark(#e2e2e2, #2b2b2b)
--xy-minimap-node-stroke-color-defaulttransparent
--xy-minimap-node-stroke-width-default2
--xy-background-color-defaultlight-dark(transparent, #141414)
--xy-background-pattern-dots-color-defaultlight-dark(#91919a, #555)
--xy-background-pattern-lines-color-defaultlight-dark(#eee, #333)
--xy-background-pattern-cross-color-defaultlight-dark(#e2e2e2, #333)
--xy-node-color-defaultlight-dark(CanvasText, #f8f8f8)
--xy-node-border-default1px solid light-dark(#1a192b, #3c3c3c)
--xy-node-background-color-defaultlight-dark(#fff, #1e1e1e)
--xy-node-group-background-color-defaultrgba(240, 240, 240, 0.25)
--xy-node-boxshadow-hover-default0 1px 4px 1px light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.08))
--xy-node-boxshadow-selected-default0 0 0 0.5px light-dark(#1a192b, #999)
--xy-node-border-radius-default3px
--xy-handle-background-color-defaultlight-dark(#1a192b, #bebebe)
--xy-handle-border-color-defaultlight-dark(#fff, #1e1e1e)
--xy-selection-background-color-defaultlight-dark(rgba(0, 89, 220, 0.08), rgba(200, 200, 220, 0.08))
--xy-selection-border-default1px dotted light-dark(rgba(0, 89, 220, 0.8), rgba(200, 200, 220, 0.8))
--xy-controls-button-background-color-defaultlight-dark(#fefefe, #2b2b2b)
--xy-controls-button-background-color-hover-defaultlight-dark(#f4f4f4, #3e3e3e)
--xy-controls-button-color-defaultlight-dark(CanvasText, #f8f8f8)
--xy-controls-button-color-hover-defaultlight-dark(CanvasText, #fff)
--xy-controls-button-border-color-defaultlight-dark(#eee, #5b5b5b)
--xy-controls-box-shadow-default0 0 2px 1px rgba(0, 0, 0, 0.08)
--xy-edge-label-background-color-defaultlight-dark(#ffffff, #141414)
--xy-edge-label-color-defaultlight-dark(CanvasText, #f8f8f8)
--xy-resize-background-color-default#3367d9

Importing only base.css provides fewer styles with some different defaults.

These variables are used to define the defaults for the various elements of React Flow. This means they can still be overridden by inline styles or custom classes on a per-element basis. If you want to override these variables, you can do so by adding:

.react-flow { --xy-node-background-color: #ff5050; }

These defaults are defined on .react-flow. Set your overrides on that element. Use the variable without the -default suffix to override its fallback value.

Overriding built-in classes

Some consider heavy use of inline styles to be an anti-pattern. In that case, you can override the built-in classes that React Flow uses with your own CSS. There are many classes attached to all sorts of elements in React Flow, but the ones you’ll likely want to override are listed below:

Class nameDescription
.react-flow

The outermost container

.react-flow__renderer

The inner container for zooming and panning (renderer pane)

.react-flow__selection

User selection

.react-flow__edges

The element containing all edges in the flow

.react-flow__edge

Applied to each Edge in the flow

.react-flow__edge.selected

Added to an Edge when selected

.react-flow__edge.animated

Added to an Edge when its animated prop is true

.react-flow__edge.updating

Added to an Edge while it gets updated via onReconnect

.react-flow__edge-path

The SVG <path /> element of an Edge

.react-flow__edge-text

The SVG <text /> element of an Edge label

.react-flow__edge-textbg

The SVG <text /> element behind an Edge label

.react-flow__connection

Applied to the current connection line

.react-flow__connection-path

The SVG <path /> of a connection line

.react-flow__nodes

The element containing all nodes in the flow

.react-flow__node

Applied to each Node in the flow

.react-flow__node.selected

Added to a Node when selected.

.react-flow__node-default

Added when Node type is "default"

.react-flow__node-input

Added when Node type is "input"

.react-flow__node-output

Added when Node type is "output"

.react-flow__node-group

Added when Node type is "group"

.react-flow__nodesselection

Nodes selection

.react-flow__nodesselection-rect

Nodes selection rect

.react-flow__handle

Applied to each <Handle /> component

.react-flow__handle-top

Applied when a handle's Position is set to "top"

.react-flow__handle-right

Applied when a handle's Position is set to "right"

.react-flow__handle-bottom

Applied when a handle's Position is set to "bottom"

.react-flow__handle-left

Applied when a handle's Position is set to "left"

.react-flow__handle.connectingfrom

Added to a Handle when a connection is being drawn from this handle.

.react-flow__handle.connectingto

Added to a Handle when a connection line is above this handle.

.react-flow__handle.valid

Added to a Handle when a connection line is above a handle and the connection is valid.

.react-flow__handle.connectionindicator

Applied when the handle can start or end a connection (connectable state).

.react-flow__background

Applied to the <Background /> component

.react-flow__minimap

Applied to the <MiniMap /> component

.react-flow__controls

Applied to the <Controls /> component

Be careful if you go poking around the source code looking for other classes to override. Some classes are used internally and are required in order for the library to be functional. If you replace them you may end up with unexpected bugs or errors!

Third-party solutions

You can choose to opt-out of React Flow’s default styling altogether and use a third-party styling solution instead. If you want to do this, you must make sure you still import the base styles.

import '@xyflow/react/base.css';

These base styles are required for React Flow to function correctly. If you don’t import them or you override them with your own styles, some things might not work as expected!

import { useCallback } from 'react'; import { ReactFlow, Background, Controls, MiniMap, useNodesState, useEdgesState, addEdge, Position, } from '@xyflow/react'; import './index.css'; const nodeDefaults = { sourcePosition: Position.Right, targetPosition: Position.Left, }; const initialNodes = [ { id: '1', position: { x: 0, y: 150 }, data: { label: 'base style 1' }, ...nodeDefaults, }, { id: '2', position: { x: 250, y: 0 }, data: { label: 'base style 2' }, ...nodeDefaults, }, { id: '3', position: { x: 250, y: 150 }, data: { label: 'base style 3' }, ...nodeDefaults, }, { id: '4', position: { x: 250, y: 300 }, data: { label: 'base style 4' }, ...nodeDefaults, }, ]; const initialEdges = [ { id: 'e1-2', source: '1', target: '2', }, { id: 'e1-3', source: '1', target: '3', }, { id: 'e1-4', source: '1', target: '4', }, ]; const Flow = () => { const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); const onConnect = useCallback( (params) => setEdges((els) => addEdge(params, els)), [], ); return ( <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} onConnect={onConnect} fitView > <Background /> <Controls /> <MiniMap /> </ReactFlow> ); }; export default Flow;

TailwindCSS

Custom nodes and edges are just React components, and you can use any styling solution you’d like to style them. For example, you might want to use Tailwind  to style your nodes:

function CustomNode({ data }) { return ( <div className="bg-background rounded-md border-2 border-stone-400 px-4 py-2 shadow-md"> <div className="flex"> <div className="bg-card flex h-12 w-12 items-center justify-center rounded-full">{data.emoji}</div> <div className="ml-2"> <div className="text-lg font-bold">{data.name}</div> <div className="text-gray-500">{data.job}</div> </div> </div> <Handle type="target" position={Position.Top} className="w-16 bg-teal-500" /> <Handle type="source" position={Position.Bottom} className="w-16 bg-teal-500" /> </div> ); }

React Flow’s styles live in the xyflow CSS layer. Declare the layer order before your imports so that Tailwind’s reset doesn’t override the default styles, but your utility classes still can.

index.css
@layer theme, base, xyflow, components, utilities; @import 'tailwindcss'; @import '@xyflow/react/style.css';

For a complete example of using Tailwind with React Flow, check out the example!