Learn
Customizing React Flow
Theming

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:

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

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

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

Built in dark and light mode

You can chose one of the built-in color modes by using the colorMode prop ('dark', 'light' or 'system') as seen in the dark mode example.

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

When you use the colorMode prop, React Flow adds a class to the root element (.react-flow) that you can use to style your flow based on the color mode:

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

Customizing with style props

The easiest way to start customising 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.

These variables are mostly self-explanatory. Below is a table of all the variables you might want to tweak and their default values for reference:

Variable nameDefault
--xy-edge-stroke-default#b1b1b7
--xy-edge-stroke-width-default1
--xy-edge-stroke-selected-default#555
--xy-connectionline-stroke-default#b1b1b7
--xy-connectionline-stroke-width-default1
--xy-attribution-background-color-defaultrgba(255, 255, 255, 0.5)
--xy-minimap-background-color-default#fff
--xy-background-pattern-dot-color-default#91919a
--xy-background-pattern-line-color-default#eee
--xy-background-pattern-cross-color-default#e2e2e2
--xy-node-color-defaultinherit
--xy-node-border-default1px solid #1a192b
--xy-node-background-color-default#fff
--xy-node-group-background-color-defaultrgba(240, 240, 240, 0.25)
--xy-node-boxshadow-hover-default0 1px 4px 1px rgba(0, 0, 0, 0.08)
--xy-node-boxshadow-selected-default0 0 0 0.5px #1a192b
--xy-handle-background-color-default#1a192b
--xy-handle-border-color-default#fff
--xy-selection-background-color-defaultrgba(0, 89, 220, 0.08)
--xy-selection-border-default1px dotted rgba(0, 89, 220, 0.8)
--xy-controls-button-background-color-default#fefefe
--xy-controls-button-background-color-hover-default#f4f4f4
--xy-controls-button-color-defaultinherit
--xy-controls-button-color-hover-defaultinherit
--xy-controls-button-border-color-default#eee
--xy-controls-box-shadow-default0 0 2px 1px rgba(0, 0, 0, 0.08)

These variables are used to define the defaults for the various elements of React Flow. This means they can still be overriden 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-default: #ff5050;
}
⚠️

Be aware that these variables are defined under .react-flow and under :root.

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-flowThe outermost container
.react-flow__rendererThe inner container
.react-flow__zoompaneZoom & pan pane
.react-flow__selectionpaneSelection pane
.react-flow__selectionUser selection
.react-flow__edgesThe element containing all edges in the flow
.react-flow__edgeApplied to each Edge in the flow
.react-flow__edge.selectedAdded to an Edge when selected
.react-flow__edge.animatedAdded to an Edge when its animated prop is true
.react-flow__edge.updatingAdded to an Edge while it gets updated via onReconnect
.react-flow__edge-pathThe SVG <path /> element of an Edge
.react-flow__edge-textThe SVG <text /> element of an Edge label
.react-flow__edge-textbgThe SVG <text /> element behind an Edge label
.react-flow__connectionApplied to the current connection line
.react-flow__connection-pathThe SVG <path /> of a connection line
.react-flow__nodesThe element containing all nodes in the flow
.react-flow__nodeApplied to each Node in the flow
.react-flow__node.selectedAdded to a Node when selected.
.react-flow__node-defaultAdded when Node type is "default"
.react-flow__node-inputAdded when Node type is "input"
.react-flow__node-outputAdded when Node type is "output"
.react-flow__nodesselectionNodes selection
.react-flow__nodesselection-rectNodes selection rect
.react-flow__handleApplied to each <Handle /> component
.react-flow__handle-topApplied when a handle's Position is set to "top"
.react-flow__handle-rightApplied when a handle's Position is set to "right"
.react-flow__handle-bottomApplied when a handle's Position is set to "bottom"
.react-flow__handle-leftApplied when a handle's Position is set to "left"
.connectingfromAdded to a Handle when a connection line is above a handle.
.connectingtoAdded to a Handle when a connection line is above a handle.
.validAdded to a Handle when a connection line is above and the connection is valid
.react-flow__backgroundApplied to the <Background /> component
.react-flow__minimapApplied to the <MiniMap /> component
.react-flow__controlsApplied 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/dist/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!

Styled Components

Many of the components you render directly, such as the <MiniMap />, accept both className and style props. This means you can use any styling solution you like, such as Styled Components (opens in a new tab):

import { MiniMap } from '@xyflow/react';
 
const StyledMiniMap = styled(MiniMap)`
  background-color: ${(props) => props.theme.bg};
 
  .react-flow__minimap-mask {
    fill: ${(props) => props.theme.minimapMaskBg};
  }
 
  .react-flow__minimap-node {
    fill: ${(props) => props.theme.nodeBg};
    stroke: none;
  }
`;

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

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 (opens in a new tab) to style your nodes:

function CustomNode({ data }) {
  return (
    <div className="px-4 py-2 shadow-md rounded-md bg-white border-2 border-stone-400">
      <div className="flex">
        <div className="rounded-full w-12 h-12 flex justify-center items-center bg-gray-100">
          {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>
  );
}
⚠️

If you want to overwrite default styles, make sure to import Tailwinds entry point after React Flows base styles.

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

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