Gradient

Slant / Media & motion

Slowly moving grainy colour fields in stepped columns, a soft glow, a low horizon or a flowing ribbon.

Demo

Usage

@tuttn/slant
import { useState } from 'react'
import { Button, Gradient } from '@tuttn/slant'

// Stepped columns, using the current theme's colours.
<Gradient />

// Two softer shapes for section backgrounds and footers.
<Gradient variant="glow" />
<Gradient variant="horizon" />

// An undulating ribbon with a second colour along its edge.
<Gradient variant="ribbon" />

// A smooth field, without the texture or column guides.
<Gradient grain={false} guides={false} />

// Pause at the current frame, then resume from the same point.
const [running, setRunning] = useState(true)
<Button aria-pressed={!running} onClick={() => setRunning(value => !value)}>
  {running ? 'Pause animation' : 'Play animation'}
</Button>
<Gradient running={running} />

// Blue Hour. These variables stay local to the artwork.
<Gradient className="blue-hour-gradient" />

.blue-hour-gradient {
  --sl-bg: #03070c;
  --sl-gradient-color: #2589ff;
  --sl-gradient-highlight: #d0e6ff;
  --sl-gradient-height: 22rem;
  --sl-gradient-grain-opacity: .28;
  --sl-gradient-duration: 12s;
}

// Dusk: warm light with an indigo edge.
<Gradient variant="ribbon" className="dusk-gradient" />

.dusk-gradient {
  --sl-bg: #19181a;
  --sl-gradient-color: #d17e74;
  --sl-gradient-secondary: #5f4f6d;
  --sl-gradient-highlight: #ffeadf;
  --sl-gradient-duration: 6s;
}

// Only name the artwork when the picture itself matters to the page.
<Gradient label="Blue light rising through seven stepped columns" />

Props

PropTypeDefaultDescription
variant'columns' | 'glow' | 'horizon' | 'ribbon''columns'Stepped columns, a soft pool of light, a bright edge, or a curved ribbon.
grainbooleantrueA fine grain over the colour.
guidesbooleantrueDotted dividers between columns; ignored by other variants.
runningbooleantrueFalse holds the current frame. Motion also pauses off screen and in a hidden tab; reduced motion shows the still artwork.
labelstring—Names the artwork as an image; omitted, it is hidden decoration.
…restOmit<HTMLAttributes<HTMLDivElement>, 'children'>—className, style, other attributes and the ref go on the root div. Put page content beside the artwork, not inside it.

Accessibility

  • Decorative and aria-hidden by default; label gives the artwork role="img" and an accessible name.
  • The artwork takes no focus. Expose a nearby pause button for its automatic motion; running=false freezes the current frame.
  • Animation pauses off screen and in hidden tabs. Reduced motion displays a static composition.

Variants

columns builds a stepped silhouette with the highest light in the centre. glow spreads the light into a soft pool, and horizon keeps a narrow band near the bottom edge. ribbon rolls a shaded surface: its crest changes shape, a darker fold opens beneath it, and pale light slides over the rim. Each shape can keep its fine grain or become smooth with grain={false}. guides controls the dotted dividers on columns; it has no effect on the other variants. Blue Hour and Dusk are example palettes you can recreate with the variables below.

Colour and sizing

The field fills its container's width and is 20rem tall by default. Set --sl-gradient-height or a regular CSS height to fit a section. --sl-gradient-color defaults to --sl-accent, --sl-gradient-highlight to --sl-text, and the background reads --sl-bg. The ribbon's second colour uses --sl-gradient-secondary, defaulting to --sl-muted. Set those variables on the component for a custom palette. --sl-gradient-grain-opacity adjusts the texture, from 0 to 1, with a default of .28.

Content and accessibility

The gradient is a separate decorative surface: it has no children, takes no focus and is hidden from screen readers. A label exposes it as a named image. Keep headings, links and other content in a sibling element, and check their contrast if you position them over the light.

Motion

All four variants move slowly while running is true, the default. Set running={false} to freeze the current frame; resuming continues from that point. The animation also pauses automatically off screen and in a hidden tab. Under prefers-reduced-motion the field holds a static composition.

Set --sl-gradient-duration to change the loop's pace. Columns, glow and horizon default to 12s; ribbon defaults to 6s. Fine grain shifts subtly as the light moves. Provide a pause button near a long-lived animated field, as in the demo. One state value can pause every gradient in a composition.

The ribbon uses a small WebGL renderer with bounded resolution. Its CSS artwork remains visible before hydration, with reduced motion, or when a graphics context is unavailable or lost. No video, image download or animation library is needed.