Skip to content

Dot pattern

A background dot pattern made with SVGs, fully customizable using Tailwind CSS.

Installation

Copy and paste the following code into your project:

DotPattern.vue
vue
<script setup lang='ts'>
import { cn } from '@/lib/utils'
import { useId } from 'vue'

interface DotPatternProps {
  width?: any
  height?: any
  x?: any
  y?: any
  cx?: any
  cy?: any
  cr?: any
  className?: string
  [key: string]: any
}
const props = withDefaults(defineProps<DotPatternProps>(), {
  width: 16,
  height: 16,
  x: 0,
  y: 0,
  cx: 1,
  cy: 1,
  cr: 1,
})

const id = `pattern-${useId()}`
</script>

<template>
  <svg
    aria-hidden="true" :class="cn(
      'pointer-events-none absolute inset-0 h-full w-full fill-neutral-400/80',
      props.className,
    )" v-bind="props"
  >
    <defs>
      <pattern
        :id="id" :width="props.width" :height="props.height" patternUnits="userSpaceOnUse"
        patternContentUnits="userSpaceOnUse" :x="props.x" :y="props.y"
      >
        <circle id="pattern-circle" :cx="props.cx" :cy="props.cy" :r="props.cr" />
      </pattern>
    </defs>
    <rect width="100%" height="100%" strokeWidth="0" :fill="`url(#${id})`" />
  </svg>
</template>

Examples

Linear Gradient

Props

PropTypeDescriptionDefault
widthanyWidth of the dot pattern16
heightanyHeight of the dot pattern16
xanyX position of the dot0
yanyY position of the dot0
cxanyX position of the circle1
cyanyY position of the circle1
cranyRadius of the circle1
classstringClass of the dot pattern-

Released under the MIT License.