Dot Pattern
magicui/dot-patternFreeComponent
A background dot pattern made with SVGs, fully customizable using Tailwind CSS.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/dot-pattern.jsonSource
1"use client"23import React, { useEffect, useId, useRef, useState } from "react"4import { motion } from "motion/react"56import { cn } from "@/lib/utils"78/**9 * DotPattern Component Props10 *11 * @param {number} [width=16] - The horizontal spacing between dots12 * @param {number} [height=16] - The vertical spacing between dots13 * @param {number} [x=0] - The x-offset of the entire pattern14 * @param {number} [y=0] - The y-offset of the entire pattern15 * @param {number} [cx=1] - The x-offset of individual dots16 * @param {number} [cy=1] - The y-offset of individual dots17 * @param {number} [cr=1] - The radius of each dot18 * @param {string} [className] - Additional CSS classes to apply to the SVG container19 * @param {boolean} [glow=false] - Whether dots should have a glowing animation effect20 */21interface DotPatternProps extends React.SVGProps<SVGSVGElement> {22 width?: number23 height?: number24 x?: number25 y?: number26 cx?: number27 cy?: number28 cr?: number29 className?: string30 glow?: boolean31 [key: string]: unknown32}3334/**35 * DotPattern Component36 *37 * A React component that creates an animated or static dot pattern background using SVG.38 * The pattern automatically adjusts to fill its container and can optionally display glowing dots.39 *40 * @component41 *42 * @see DotPatternProps for the props interface.43 *44 * @example45 * // Basic usage46 * <DotPattern />47 *48 * // With glowing effect and custom spacing49 * <DotPattern50 * width={20}51 * height={20}52 * glow={true}53 * className="opacity-50"54 * />55 *56 * @notes57 * - The component is client-side only ("use client")58 * - Automatically responds to container size changes59 * - When glow is enabled, dots will animate with random delays and durations60 * - Uses Motion for animations61 * - Dots color can be controlled via the text color utility classes62 */6364export function DotPattern({65 width = 16,66 height = 16,67 x = 0,68 y = 0,69 cx = 1,70 cy = 1,71 cr = 1,72 className,73 glow = false,74 ...props75}: DotPatternProps) {76 const id = useId()77 const containerRef = useRef<SVGSVGElement>(null)78 const [dimensions, setDimensions] = useState({ width: 0, height: 0 })7980 useEffect(() => {81 const updateDimensions = () => {82 if (containerRef.current) {83 const { width, height } = containerRef.current.getBoundingClientRect()84 setDimensions({ width, height })85 }86 }8788 updateDimensions()89 window.addEventListener("resize", updateDimensions)90// … truncated
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
