shadcn.io is an independent project built on shadcn/ui
Terrain Background for Svelte
Cut-paper layers of a slowly shifting landscape, each casting a soft shadow. For Svelte with Ark UI, when a section needs depth and color.
On this page10 sections
Cut paper: a height field that shifts slowly in place, drawn as sheets stacked from the surface up. Each sheet is one color of the palette and throws a soft shadow on the sheet under it, long where its edge faces the light and a thin line of contact where it faces away. It's a GLSL scene on WebGL2 with no dependency. The lowest level is the surface itself, so the stack sits on a light page or a dark one, pale at the bottom and full color at the top. The pointer is a lamp held over the paper: the shadows lean away from it.
Use it behind a hero, a feature section or a card that wants depth and color. For the same land as thin contour lines with no fill, use Topography; for ridgelines seen from the side, fading into haze, Dunes; for flat triangles shaded by a moving light, Facets. With reduced motion it holds one still frame.


Installation
Usage
<script lang="ts">
import { Terrain } from "@/components/ui/terrain";
</script>
<Terrain class="flex min-h-[32rem] flex-col items-center justify-center">
<h1 class="text-5xl font-semibold">Every revision, stacked where you can see it</h1>
</Terrain>
Terrain is a container: whatever you put inside sits on top of the paper, 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
<Terrain /><Terrain
colors={["#fcd34d", "#fb923c", "#ef4444", "#9f1239"]}
cover={0.7}
layers={8}
roughness={0.5}
/><Terrain
colors={["#6366f1", "#a855f7", "#ec4899", "#fb923c"]}
layers={7}
scale={0.6}
softness={1}
/><Terrain
colors={["#86efac", "#22c55e", "#15803d"]}
cover={0.2}
layers={4}
scale={1.3}
/><Terrain
colors={["var(--foreground)", "var(--foreground)"]}
intensity={0.12}
shadow={1}
softness={0.7}
/><Terrain
colors={["#fde68a", "#f59e0b", "#b45309", "#7c2d12"]}
layers={12}
scale={0.7}
shadow={0.35}
softness={0.15}
warp={0.8}
/><Terrain
colors={["#f5d0a9", "#e7a977", "#c2703d"]}
layers={3}
roughness={1}
shadow={0.8}
softness={0.3}
/>Each preset is a set of props, so copy one and keep tuning. Lagoon is the default. Paper takes one color from your theme at low strength, so the sheets are told apart by their shadows alone. Dusk uses seven large sheets with long shadows, Islands leaves most of the surface clear, Torn has three sheets with ragged edges, and Strata packs twelve thin ones.
Examples
Hero
The default look behind a headline: five sheets from emerald to indigo. On a light surface they're tints, so dark copy reads on every sheet; on a dark one they're deep shades under light copy. The chip and the second button have a translucent ground of their own.
Dusk
Four colors from indigo to orange over layers={7}. scale={0.6} makes the shapes larger than the default and softness={1} lets the shadows spread as if the sheets were held well apart.
In a card
One theme color for every sheet and intensity={0.12} leave the paper almost the color of the surface, and shadow={1} draws the stack with shadows alone. fade="bottom" clears the lower edge for the copy.
Customization
Every color is a CSS color, so a theme variable works and follows a theme switch. colors runs from the lowest sheet to the highest, mixed in OKLab when there are more sheets than colors. layers sets how many sheets there are, cover how much of the surface they hide, and shadow, softness and angle how dark the shadows are, how far they spread and where the light comes from.
The surface is the root's own background, bg-background by default. Give the root another (bg-slate-950, a brand color) and the lowest level shows that. fade masks an edge, opacity turns the whole effect down, and grain adds film grain, which suits paper.
<Terrain
class="min-h-[32rem] bg-slate-950"
colors={["var(--chart-1)", "var(--chart-2)", "var(--chart-3)"]}
fade="bottom"
grain={0.15}
roughness={0.5}
/>
Performance
It's one WebGL2 canvas and one fragment shader. The land is three samples of simplex noise, five while warp is above 0, and a pixel reads it once, plus once more where a shadow may fall, to check that the sheet above is really there. Torn edges add two samples while roughness is above 0: twelve at most with the defaults. 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 paper is decoration: the canvas is 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.
Use the foreground color (text-foreground) for copy on top. On the default look the darkest point, a shadow on the top sheet, leaves foreground text at 6.9:1 on a light surface, and the brightest sheet leaves it at 6:1 on a dark one. intensity above 1 makes the sheets more solid and lowers both: check your own palette, or give the copy a ground of its own.
FAQ
How do I change the colors?
Pass two to eight CSS colors to colors, from the lowest sheet to the highest. With more sheets than colors, the sheets between take a mix. Hex, oklch() and theme variables such as var(--chart-1) all work, and a variable follows your theme when it changes. intensity sets how solid the paper is over the surface.
Does it work on a light page?
Yes, with no prop to set. The lowest level is the surface itself and each sheet is painted over it more strongly than the one below, so the same palette gives pale tints on white and deep shades on near-black. Shadows are darker on a dark surface, where they'd otherwise be lost. Set the surface with a class on the component, such as bg-slate-950.
How do I make the layers look further apart?
Raise softness: the shadows spread up to 36 px from an edge that faces the light, as if the sheets were held apart. shadow sets how dark they are and angle where the light comes from. highlight adds a thin lit rim on the side of each edge that faces the light, which reads as the thickness of the paper.
Can the edges look torn?
Yes: roughness. At 0 the sheets are cut with a blade, and at 1 the edges waver by a few pixels, like paper torn by hand. The tear is sized in CSS pixels, so it looks the same whatever scale you give the land.
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. The land is sized in CSS pixels, so a bigger box shows more of it and the shapes keep their size. Lower scale for larger, calmer shapes on a wide page.
Will it slow my page down?
It's a moderate shader: up to twelve samples of noise a pixel with the defaults, on the GPU, and nothing at all while it's off screen or the tab is hidden. If a device can't keep up, it renders fewer pixels by itself. For a phone-first page, warp={0} and roughness={0} halve the work.
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.
What does the pointer do, and what about reduced motion?
The pointer is a lamp: while it's over the box the light comes from it, so every shadow leans away from the pointer. A press sends a swell across the land that lifts the sheets as it passes. interactive={false} turns both off, and touch never triggers them. With reduced motion the scene holds one still frame and ignores the pointer.
API Reference
Terrain
data-slot="terrain"
angle?number
Where the light falls from, in degrees: 0 is the right, 90 the top, 180 the left. The shadows fall the other way.
- Default
120
colors?string[]
Two to eight CSS colors for the sheets, from the lowest to the highest.
Theme variables such as var(--primary) follow your theme.
- Default
["#34d399", "#14b8a6", "#0ea5e9", "#6366f1"]
cover?number
How much of the box the sheets cover, from 0 (islands on the surface) to 1 (no surface left to see).
- 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.
grain?number
Film grain over the scene, from 0 to 1.
- Default
0
highlight?number
How strongly the lit rim of each sheet's edge shows, from 0 to 1.
- Default
0.5
intensity?number
How solid the sheets' color is over the surface.
- 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
layers?number
How many sheets are stacked on the surface, from 2 to 12.
- Default
5
opacity?number
How strongly the scene shows over the surface, from 0 to 1.
- Default
1
paused?boolean
Holds the current frame.
- Default
false
quality?number
Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.
- Default
1
roughness?number
How ragged the edges are, from 0 (cut with a blade) to 1 (torn by hand).
- Default
0.15
scale?number
The size of the land: higher packs more, smaller shapes.
- Default
1
seed?number
Another layout of the same look, from 0 to 20.
- Default
0
shadow?number
How dark the shadow under each sheet is, from 0 (flat color) to 1.
- Default
0.6
softness?number
How far the shadows spread, from 0 (sheets pressed flat) to 1 (sheets held well apart).
- Default
0.5
speed?number
Animation speed: 1 is normal, 0 holds the frame.
- Default
1
time?number
A fixed moment, in seconds: draws it and doesn't animate.
warp?number
How much the land is twisted, from 0 (plain hills) to 1 (swirling folds).
- Default
0.3











