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 'reactflow/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
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 'reactflow'
const styles = {
background: 'red',
width: '100%',
height: 300,
};
export default function Flow() {
return <ReactFlow style={styles} nodes={[...]} edges={[...]} />
}
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 name | Description |
---|---|
.react-flow | The outermost container |
.react-flow__renderer | The inner container |
.react-flow__zoompane | Zoom & pan pane |
.react-flow__selectionpane | Selection 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 onEdgeUpdate |
.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__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-connecting | Applied when a connection line is above a handle. |
.react-flow__handle-valid | Applied when a connection line is above a handle and the connection is valid |
.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 'reactflow/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 'reactflow';
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 'reactflow/dist/style.css';
import 'tailwind.css';
For a complete example of using Tailwind with React Flow, check out the example!