Theming
Vue Flow comes with minimal default styles and was designed to be fully customizable. Many of our users fully transform the look and feel of Vue Flow to match their own brand or design system. This guide will introduce you to the different ways you can customize Vue Flow’s appearance.
Default styles
Vue 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 '@xyflow/vue/style.css';The shorter @xyflow/vue/style.css import is available in Vue Flow 2.
The previous @xyflow/vue/dist/style.css path is still supported.
You’ll typically load these default styles by importing them in your main.ts,
App.vue, or another entry point.
Without dipping into custom nodes and edges, there are several ways you can style Vue Flow’s basic look:
- Passing inline styles through
styleprops - Overriding the built-in classes with custom CSS
- Overriding the CSS variables Vue Flow uses
- Using scoped styles in your Vue components for custom nodes and edges
Using our theme
For xyflow’s themed appearance, import xy-theme.css in place of style.css:
import '@xyflow/vue/xy-theme.css';This stylesheet builds on base.css and includes the styles needed for Vue 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 Vue Flow 2, 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/vue/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 .
Base styles
If you just want to load the very basic styles that are necessary for Vue Flow to work, you can import the base styles instead:
import '@xyflow/vue/base.css';These base styles are required for Vue 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!
Customization
Built in dark and light mode
Vue 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':
<script setup lang="ts">
import { VueFlow } from '@xyflow/vue';
import '@xyflow/vue/style.css';
</script>
<template>
<VueFlow force-color-mode="dark" :nodes="[]" :edges="[]" />
</template>You can use light-dark() in your own CSS to follow the same color scheme:
.vue-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 on <VueFlow /> and other components to inline your own CSS.
<script setup lang="ts">
import { VueFlow } from '@xyflow/vue';
import '@xyflow/vue/style.css';
const styles = {
background: 'red',
width: '100%',
height: '300px',
};
</script>
<template>
<VueFlow :style="styles" :nodes="[]" :edges="[]" />
</template>A background set this way styles the outer element. The flow canvas is painted by an inner pane, so set the
--xy-background-color CSS variable to change the canvas color.
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.
Importing only base.css provides fewer styles with some different defaults.
These variables are used to define the defaults for the various elements of Vue Flow. This means they can still be overridden by inline styles or custom classes on a per-element basis. If you want to override a variable, you can do so by adding:
.vue-flow {
--xy-node-background-color: #ff5050;
}These defaults are defined on .vue-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 Vue Flow uses with your own CSS. There are many classes attached to all sorts of elements in Vue Flow, but the ones you’ll likely want to override are listed below:
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!
Scoped styles for custom nodes and edges
Custom nodes and edges are Vue components. You can use
<style scoped> in those
components to keep styling isolated from the rest of your app.
Third-party solutions
You can choose to opt out of Vue 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 (@xyflow/vue/base.css).
TailwindCSS
Custom nodes and edges are just Vue 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:
<script setup lang="ts">
import type { NodeProps } from '@xyflow/vue';
import { Handle, Position } from '@xyflow/vue';
defineProps<NodeProps>();
</script>
<template>
<div class="px-4 py-2 shadow-md rounded-md bg-background border-2 border-stone-400">
<div class="flex">
<div class="rounded-full w-12 h-12 flex justify-center items-center bg-card">
{{ data.emoji }}
</div>
<div class="ml-2">
<div class="text-lg font-bold">{{ data.name }}</div>
<div class="text-gray-500">{{ data.job }}</div>
</div>
</div>
<Handle type="target" :position="Position.Top" class="w-16 bg-teal-500 rounded-none border-none" />
<Handle type="source" :position="Position.Bottom" class="w-16 bg-teal-500 rounded-none border-none" />
</div>
</template>Vue 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.
@layer theme, base, xyflow, components, utilities;
@import 'tailwindcss';
@import '@xyflow/vue/style.css';