Skip to content

shadcn.io is an independent project built on shadcn/ui

Pro

Fractal Background for Svelte

A Julia set morphs slowly, with a smooth glow and a fine edge, in your colors. For Svelte with Ark UI, when a page is about growth or math.

On this page10 sections
UI library: Ark UI

A Julia set morphs slowly across the lower half of the box: a glow that rises smoothly toward the set, a thin line on its edge and a soft fill inside. It's a GLSL scene on WebGL2 with no dependency, and the count of iterations it colors by is continuous, so the glow has no steps unless you ask for them. On a dark surface the edge is the brightest color of the palette; on a light one it's the deepest, like ink on a wash. The pointer nudges the shape.

Use it behind a hero for a product about growth, rules or mathematics, or as a close-up texture with zoom: by default the set fills the lower half of the box, its spiral arms reaching half way up, and leaves the top to the copy. For thick paint wound in a spiral, use Swirl; for contour lines of a shifting height field, Topography; for patterns that grow from a simulation, Reaction Diffusion. With reduced motion it holds one still frame.

Playground
Fractal Background, still
Customize

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

<script lang="ts">
import { Fractal } from "@/components/ui/fractal";
</script>
<Fractal class="flex min-h-[36rem] flex-col items-center pt-16">
  <h1 class="text-5xl font-semibold">Simple rules, endless detail</h1>
</Fractal>

Fractal is a container: whatever you put inside sits on top of the set, in normal flow. It fills its own box, so give it a height or content. For a backdrop behind the whole page, render it empty with className="fixed inset-0 -z-10".

Presets

Spiralthe default lookTry it
<Fractal />
ContourTry it
<Fractal
  bands={1}
  colors={["#1e3a8a", "#3b82f6", "#a5f3fc"]}
  edge={0.2}
  spread={1.6}
/>
DendriteTry it
<Fractal
  angle={20}
  colors={["#0e7490", "#22d3ee", "#cffafe"]}
  edge={1}
  placement="center"
  spread={1.4}
  variant="dendrite"
  zoom={1.1}
/>
EmberTry it
<Fractal
  colors={["#7c2d12", "#ea580c", "#fbbf24", "#fef3c7"]}
  placement="top"
/>
MonoTry it
<Fractal
  colors={["var(--muted-foreground)", "var(--foreground)"]}
  edge={0.8}
  fill={0.08}
/>
RabbitTry it
<Fractal
  colors={["#9d174d", "#fb7185", "#fed7aa"]}
  fill={0.5}
  placement="right"
  variant="rabbit"
  zoom={1.2}
/>
Whirlthe default lookTry it
<Fractal centerX={0.42} centerY={0.2} placement="center" zoom={2.7} />

Each preset is a set of props, so copy one and keep tuning. Spiral is the default. Dendrite draws a thin branching set through the middle of the box, which stays quiet behind copy; Whirl frames two spiral arms close up, edge to edge; Contour breaks the glow into eight steps (bands); Rabbit fills the three-lobed set on the right edge; and Mono takes its colors from your theme.

Examples

Hero

The default look with no props: the set lies along the bottom of the box, wider than the box itself, with its tallest spiral reaching half way up, and the copy sits above it on the plain surface. The chip and the second button have a translucent ground of their own.

Preview width

Dendrite

variant="dendrite" is the set with no inside, only branches. Here it crosses a slate surface through the middle (placement="center"), turned 20 degrees, in teal and cyan with the edge line at full strength.

Preview width

In a card

bands={1} turns the glow into contour steps, with a longer reach (spread={1.6}), a fainter edge and a blue palette, along the bottom of a card.

Preview width

Customization

colors runs from the glow far from the set to its edge, and any CSS color works, theme variables included. The end of the list that stands out more against the surface takes the edge, so one palette from deep to bright reads as light on a dark page and as ink on a light one, and a theme switch turns it around. variant picks the set, placement the edge it lies on (it reaches about half way into the box from there), and centerX, centerY and zoom frame a part of it.

The surface is the root's own background, bg-background by default. Give the root another (bg-slate-950, a gradient) and the scene adapts. fade masks an edge, opacity turns the whole effect down, and grain adds film grain.

<Fractal
  class="min-h-[32rem] bg-slate-950"
  colors={["var(--chart-3)", "var(--chart-1)", "#fef3c7"]}
  grain={0.15}
  placement="right"
/>

Performance

It's one WebGL2 canvas and one fragment shader: each pixel iterates z = z² + c until it escapes, at most 100 times by default. Most of the box escapes in under 20 iterations; only the inside of the set pays the full count. detail bounds it between 40 and 160. It draws only while it's on screen and the tab is visible, shares one frame loop with every other background on the page, and lowers its own resolution if frames run long. quality sets the render scale yourself, and paused holds the frame.

Accessibility

The set is decoration: it's hidden from assistive tech and lets every click through to your content. With reduced motion it draws one still frame and ignores the pointer. Nothing flashes: the shape changes over tens of seconds.

Keep copy off the set. On the default look, text in text-foreground in the top 45% of the box measures 18:1 or more on both surfaces. Averaged over the set itself it is 12:1 on a light surface and 6:1 on a dark one, but the edge is the color that stands out most against the surface, as the text is: where a stroke crosses it, it has about 2.4:1 on light and next to none on dark, where the edge is nearly white. Use placement to move the set, or lower edge and intensity, when copy has to sit on it.

FAQ

How do I change the colors?

Pass two to eight CSS colors to colors, from the glow far from the set to its edge. Hex, oklch() and theme variables such as var(--primary) all work. The scene puts the end of the list that stands out more against the surface on the edge, so you can write one palette from deep to bright and use it on both themes.

Does it work on a light page?

Yes, with no prop to set. On a dark surface the glow adds light and the edge is the brightest color. On a light one the glow is a pale wash and the edge takes the deepest color, so the set reads like ink on paper. Set the surface with a class on the component, such as bg-slate-950.

How do I zoom in on a part of the set?

Set placement="center", then centerX and centerY to the point of the set to look at and zoom to how close. The set spans about -1.6 to 1.6 across and -1 to 1 upward, with 0 at its center. The Whirl preset looks at 0.42, 0.2 at zoom={2.7}. Past zoom={4} the default detail runs out of structure to show.

Why are there no color bands, and how do I get them?

The scene colors by a continuous count of iterations, not a whole number, so the glow is a smooth gradient. bands brings steps back on purpose: at 1 the glow has eight flat levels from the far glow to the set, with edges one pixel soft, and values in between give soft terraces.

Can the shape change faster or further, or not at all?

morph sets how far the set's constant wanders from its own value: 0 keeps the shape still, 1 is the widest path each variant allows before the set starts to break up. speed sets how fast it travels that path. The path is closed and continuous, so the motion never jumps.

Will it slow my page down?

At the default detail it is a light scene: most pixels leave the loop within 20 iterations. A view that is mostly inside the set, such as a filled Rabbit at a high zoom, runs the full count on every pixel, so lower detail there or set quality={0.75}. Off screen and in a hidden tab it draws nothing.

Does it work with Next.js and server components?

Yes. Import it into a server component and it renders its box and your content on the server; the canvas starts in the browser and fades in over the surface. It needs WebGL2, which every current browser has. Without it the box keeps its background, or the fallback you pass.

How do I put it behind the whole page?

Render it empty with className="fixed inset-0 -z-10". It still follows the pointer there, since it listens on the window. To put it behind one section, wrap that section's content in it and give it a height, such as min-h-svh.

API Reference

Fractal

data-slot="fractal"

PropType
angle?number

How far the set is turned in the box, in degrees, from -180 to 180.

Default
0
bands?number

How much the smooth glow breaks into contour steps, from 0 (smooth) to 1 (one step for each iteration).

Default
0
centerX?number

How far the view is moved across the set's own plane, to frame another part of it: the set spans about -1.6 to 1.6.

Default
0
centerY?number

How far the view is moved up the set's own plane, to frame another part of it: the set spans about -1 to 1.

Default
0
colors?string[]

Two to eight CSS colors, from the glow far from the set to its edge. The end of the list that stands out more against the surface takes the edge, so one palette from deep to bright reads on dark and on light.

Default
["#3a36c9", "#8a5cf6", "#f472b6", "#ffd9a8"]
detail?number

How fine the structure is, from 0 to 1: it bounds the iterations, from 40 to 160 a pixel.

Default
0.5
edge?number

How strongly the thin line on the set's edge shows, from 0 to 1.

Default
0.5
fade?"none" | "radial" | "top" | "bottom" | "left" | "right"

Which edges fade out to the surface: radial keeps the middle, the others name the side that fades.

Type
"none" | "radial" | "top" | "bottom" | "left" | "right"
Default
"none"
fallback?string

What shows until the first frame and in browsers without WebGL2: a CSS background value that looks like the scene.

fill?number

How solid the inside of the set is, from 0 (hollow) to 1.

Default
0.35
grain?number

Film grain over the scene, from 0 to 1.

Default
0
intensity?number

How bright or strong the glow is, from 0 to 2.

Default
1
interactive?boolean

Whether the scene follows the pointer and answers a press. Touch never moves it, so scrolling a page on a phone isn't disturbed.

Default
true
morph?number

How far the set wanders from its shape as it morphs, from 0 (still) to 1.

Default
0.6
opacity?number

How strongly the scene shows over the surface, from 0 to 1.

Default
1
paused?boolean

Holds the current frame.

Default
false
placement?"bottom" | "top" | "left" | "right" | "center"

Where the set sits: along the bottom or the top edge, reaching half way into the box, along the left or the right one, or whole in the center.

Type
"bottom" | "top" | "left" | "right" | "center"
Default
"bottom"
quality?number

Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.

Default
1
speed?number

Animation speed: 1 is normal, 0 holds the frame.

Default
1
spread?number

How far the glow reaches from the set, from 0.3 to 2.

Default
1
time?number

A fixed moment, in seconds: draws it and doesn't animate.

variant?"spiral" | "rabbit" | "dendrite" | "pearls"

Which Julia set it draws: spiral arms, the rabbit's lobes, a branching dendrite or a string of pearls.

Type
"spiral" | "rabbit" | "dendrite" | "pearls"
Default
"spiral"
zoom?number

How close the view is, from 0.4 to 4: higher frames less of the set, larger.

Default
1