shadcn.io is an independent project built on shadcn/ui
Underwater Background for Vue
Rays of light slant down through water that deepens toward the bottom. For Vue with Ark UI, when a hero needs calm depth under its copy.
On this page10 sections
Water seen from inside it: rays of light fan down from a point above the surface and die away with depth, the surface shimmers along the top of the box, a few motes drift at three distances and light up where a ray passes, and the color deepens toward the bottom. It's a GLSL scene on WebGL2 with no dependency. On a light surface it's sunlit shallows with white light, on a dark one deep blue water with pale aqua light. The rays lean a little with the pointer, and the motes near it brighten.
Use it behind a hero or a card whose copy sits low, in the deep part. For the same water seen from above the horizon, use Ocean; for the net of light on a pool floor, Caustics; for shafts of light through haze with no water, Corona. With reduced motion it holds one still frame.


Installation
Usage
<script setup lang="ts">
import { Underwater } from "@/components/ui/underwater";
</script>
<template>
<Underwater class="flex min-h-[34rem] flex-col items-center justify-end gap-4 pb-16">
<h1 class="text-5xl font-semibold">Learn to dive in clear water</h1>
<p class="text-foreground/80">Four mornings in the bay.</p>
</Underwater>
</template>
Underwater is a container: whatever you put inside sits on top of the water, 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
<Underwater /><Underwater
:caustics="0.1"
:colors="['#0b3552', '#061a2e', '#01050c']"
:haze="0.2"
lightColor="#9fd8ff"
:particles="1.6"
:rays="0.5"
:reach="0.45"
/><Underwater
:angle="0"
:haze="0.9"
:position="0.5"
:rays="1.6"
:reach="1"
:scale="0.4"
:softness="0.2"
/><Underwater
:colors="['#ffb38a', '#b05a8a', '#2b1c4f']"
lightColor="#ffe2b8"
/><Underwater
:angle="8"
:colors="['#9fd98a', '#3f8f5c', '#0f3a2e']"
lightColor="#eaffc2"
:particles="1.4"
:scale="1.6"
/><Underwater
:caustics="0"
:colors="['var(--muted)', 'var(--background)']"
lightColor="var(--foreground)"
:rays="0.35"
/><Underwater
:angle="-20"
:colors="['#bff5e6', '#5fd6c4', '#1f9aa8']"
lightColor="#fffbe0"
:position="0.7"
:rays="1.4"
/>Each preset is a set of props, so copy one and keep tuning. Shallows is the default and follows the surface. Abyss is deep water where the rays barely reach and the motes fall like marine snow, Beam gathers the light into two or three wide shafts from straight above, Dusk and Kelp change the water itself, and Mono takes its water and its light from your theme.
Examples
Hero
The light is at the top and thins out by the middle of the box, so the copy sits at the bottom, where the water is deep and even. The headline and the line under it use the foreground color; the chip and the second button have a translucent ground of their own.
Dusk
colors runs from the surface down to the deep: here a sunset through the water, peach to plum to violet, with a warm lightColor. The palette is the same on a light page and a dark one.
In a card
position={0.7} moves the point where the light enters to the right and angle={-14} leans the rays back to the left, away from the two lines of copy at the bottom of the card.
Customization
Every color is a CSS color, so a theme variable works and follows a theme switch. colors is the water from the surface to the deep, mixed in OKLab, and lightColor is the rays, the shimmer and the motes. Leave them out and the scene picks sunlit shallows on a light surface and deep blue on a dark one. The water is painted over the whole box, so the colors you pass are the colors you get.
rays, reach, scale and softness shape the light; depth sets how soon the deep color takes over; caustics, haze and particles each go to 0 to drop a layer. fade masks an edge into the page, opacity turns the whole scene down and grain adds film grain.
<Underwater
className="min-h-[32rem]"
caustics={0}
colors={["var(--muted)", "var(--background)"]}
lightColor="var(--foreground)"
rays={0.35}
/>Performance
It's one WebGL2 canvas and one fragment shader with no loop: three samples of simplex noise for the rays, two more for the shimmer in the upper half of the box only, three hash lookups for the motes and two taps of the palette. 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 scene 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 rays brighten and dim over seconds, and a mote takes half a minute or more to come and go.
Put copy in the lower half and use the foreground color (text-foreground). Measured on the default look, the lower half keeps at least 8.5:1 on a light surface; on a dark one 99% of it keeps at least 7.4:1 and the brightest mote 4.2:1. The upper half of a dark box holds the rays and the shimmer, which fall to 1.3:1, so keep copy below them or lower rays and reach.
FAQ
How do I change the colors?
colors takes two to eight CSS colors for the water, from the surface at the top of the box to the deep at the bottom, and lightColor is the rays, the shimmer and the motes. Hex, oklch() and theme variables all work. A light surface color with a dark deep color reads as real depth; the Dusk and Kelp presets are only a palette and a light color.
What does it look like in dark mode?
With no colors passed, the scene reads the surface behind it. On a light page it's sunlit shallows: pale aqua at the surface, clear turquoise below, white light. On a dark page it's deep water: teal blue at the surface down to near-black navy, with pale aqua light. Pass your own colors and they're used on both.
Where should the copy go?
Low in the box. The rays enter at the top and fade out by the middle (reach is 0.7 by default), and the bottom is the deepest, most even color. Align content to the bottom, as the hero demo does with justify-end. If the copy has to sit higher, lower rays or reach, or move the light aside with position.
How do I get a few strong shafts or many fine ones?
scale sets how many shafts fit in the fan: 0.4 gives two or three wide ones, 3 gives dozens of fine ones. softness blurs their edges, from crisp at 0 to one wash of light at 1. angle slants them, position moves the point they come from, and reach sets how deep they go. The Beam preset is scale={0.4} and softness={0.2} from straight above.
How do I put it behind the whole page?
Render it empty with className="fixed inset-0 -z-10". It still answers the pointer there, since it listens on the window. The rays and the depth follow the box, so a tall phone screen gets a longer fall of light; the motes stay the same size in pixels.
Will it slow my page down?
It's a light shader: five noise samples a pixel at most and no loop, 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. quality={0.75} draws a little over half the pixels, and this scene is soft enough that it's hard to tell.
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, such as a gradient from the surface color to the deep one.
API Reference
Underwater
data-slot="underwater"
angle?number
The slant of the rays, in degrees from -60 to 60: 0 falls straight down, a positive angle leans them to the right.
- Default
16
caustics?number
How strongly the surface shimmers along the top of the box, from 0 to 1.
- Default
0.6
colors?string[]
Two to eight CSS colors for the water, from the surface down to the deep. Without it the scene picks its own: sunlit shallows on a light surface (the default below) and deep blue water on a dark one.
- Default
["#c4eff8", "#8bd8ea", "#50b6d3"]
depth?number
How soon the water deepens, from 0 (the surface's color most of the way down) to 1 (the deep color from the middle of the box).
- 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
haze?number
How much scattered light glows where the rays enter the water, from 0 to 1.
- Default
0.5
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
lightColor?string
The color of the light: the rays, the shimmer and the motes. Without it the scene uses white on a light surface (the default below) and a pale aqua on a dark one.
- Default
"#ffffff"
opacity?number
How strongly the scene shows over the surface, from 0 to 1.
- Default
1
particles?number
How many motes drift in the water, from 0 (none) to 2.
- Default
1
paused?boolean
Holds the current frame.
- Default
false
position?number
Where the light enters across the top of the box, from 0 (left) to 1 (right).
- Default
0.32
quality?number
Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.
- Default
1
rays?number
How bright the rays are, from 0 (none) to 2.
- Default
1
reach?number
How far down the rays reach, as a share of the box, from 0.2 to 1.2.
- Default
0.7
scale?number
The width of the rays: higher packs more, thinner shafts into the fan.
- Default
1
size?number
The size of the motes, in CSS pixels, from 1 to 6.
- Default
2.5
softness?number
How blurred the edges of the rays are, from 0 (crisp shafts) to 1 (one soft wash of light).
- Default
0.4
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.











