Skip to Content
Vue Flow v2 is here and joins xyflow! Read more here →
ReferenceComponents

<Background />

Source on GitHub 

The <Background /> component makes it convenient to render different types of backgrounds common in node-based UIs. It comes with three variants: lines, dots and cross.

<script setup lang="ts"> import { shallowRef } from 'vue'; import { Background, VueFlow } from '@xyflow/vue'; const nodes = shallowRef([]); const edges = shallowRef([]); </script> <template> <VueFlow v-model:nodes="nodes" v-model:edges="edges"> <Background color="#ccc" variant="dots" /> </VueFlow> </template>

Props

The type for props of <Background /> component is exported as BackgroundProps.

NameTypeDefault
idstring

<Background> component id

This is necessary when you have multiple flows with backgrounds visible at the same time. If no id is explicitly assigned, an auto-generated one is used.

`pattern-${vueFlowId}${id ? `-${id}` : ''}`
variantBackgroundVariant

The background pattern variant BackgroundVariant

'dots'
gapnumber | number[]

The background pattern gap

Can be either a number or [xGap: number, yGap: number], defining the gap on the X and Y axis respectively

20
sizenumber

The radius of each dot or the size of each rectangle if the dots or cross variant is used.

Defaults to 1 or 6 respectively, and is ignored by the lines variant.

lineWidthnumber

The stroke thickness used when drawing the pattern.

1
colorstring

The background pattern color

This only changes the color of the pattern, not the background color itself - use BackgroundProps.bgColor for that.

bgColorstring

The background color

patternClassNamestring

Class applied to the pattern

xnumber

Background x-coordinate (offset x)

0
ynumber

Background y-coordinate (offset y)

0
offsetnumber | [number, number]

Background pattern offset

0

Examples

Multiple backgrounds

It is possible to render multiple <Background /> components by giving each one a distinct id. Combining variants — for example a fine dots grid over a wider lines grid — makes for a nice layered effect.

<script setup lang="ts"> import { shallowRef } from 'vue'; import { Background, VueFlow } from '@xyflow/vue'; const nodes = shallowRef([]); const edges = shallowRef([]); </script> <template> <VueFlow v-model:nodes="nodes" v-model:edges="edges"> <Background id="1" :gap="10" color="#f1f1f1" variant="lines" /> <Background id="2" :gap="100" color="#ccc" variant="lines" /> </VueFlow> </template>