Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A background grid pattern made with SVGs, fully customizable using Tailwind CSS.
grid-pattern.svelte
<script lang="ts"> import { GridPattern } from "$lib/components/magic/grid-pattern/index.js"; import { cn } from "$lib/utils.js";</script>
<div class="bg-background relative flex h-125 w-full flex-col items-center justify-center overflow-hidden rounded-lg border"> <GridPattern squares={[ [4, 4], [5, 1], [8, 2], [5, 3], [5, 5], [10, 10], [12, 15], [15, 10], [10, 15], [15, 10], [10, 15], [15, 10], ]} class={cn( "[mask-image:radial-gradient(400px_circle_at_center,white,transparent)]", "inset-x-0 inset-y-[-30%] h-[200%] skew-y-12" )} /></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/grid-pattern.json
Copy the Source Code
Copy and paste the following code into your project:
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { ClassValue, SVGAttributes } from "svelte/elements";
interface GridPatternProps extends SVGAttributes<SVGSVGElement> { width?: number; height?: number; /** * The x-offset of the pattern */ x?: number; /** * The y-offset of the pattern */ y?: number; /** * Array of [x, y] coordinates for highlighted squares */ squares?: Array<[x: number, y: number]>; /** * Stroke dash array for dashed lines */ strokeDashArray?: string; class?: ClassValue; }
let { width = 40, height = 40, x = -1, y = -1, strokeDashArray = "0", squares, class: className, ...props }: GridPatternProps = $props();
const id = $props.id();</script>
<svg aria-hidden="true" class={cn( "pointer-events-none absolute inset-0 h-full w-full fill-gray-400/30 stroke-gray-400/30", className )} {...props}> <defs> <pattern {id} {width} {height} patternUnits="userSpaceOnUse" {x} {y}> <path d={`M.5 ${height}V.5H${width}`} fill="none" stroke-dasharray={strokeDashArray} /> </pattern> </defs> <rect width="100%" height="100%" stroke-width={0} fill={`url(#${id})`} /> {#if squares} <svg {x} {y} class="overflow-visible"> {#each squares as [squareX, squareY], i (`${squareX}-${squareY}-${i}`)} <rect stroke-width="0" width={width - 1} height={height - 1} x={squareX * width + 1} y={squareY * height + 1} /> {/each} </svg> {/if}</svg> export { default as GridPattern } from "./grid-pattern.svelte";Folder Structure
src/└── lib/ └── components/ └── magic/ └── grid-pattern/ ├── grid-pattern.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/grid-pattern/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { GridPattern } from "#lib/components/magic/grid-pattern/index.js";</script>
<div class="relative h-64 overflow-hidden"> <GridPattern class="absolute inset-0" /></div>Props
Grid Pattern Props
Props for the GridPattern component
| Name | Type | Default | Description |
|---|---|---|---|
width | number | 40 | The width of each grid cell |
height | number | 40 | The height of each grid cell |
x | number | -1 | The x-offset of the pattern |
y | number | -1 | The y-offset of the pattern |
squares | Array<[x: number, y: number]> | undefined | Array of [x, y] coordinates for highlighted squares |
strokeDasharray | string | "0" | Stroke dash array for dashed lines |
class | ClassValue | undefined | Additional CSS classes |