Skip to content

Presets

Ready-to-use gradient strings and dynamic generators.

Fixed gradient strings

ts
import {
  sunsetGradient,
  oceanGradient,
  auroraGradient,
  fireGradient,
  midnightGradient,
  peachGradient,
  mintGradient,
  rainbowGradient,
  glowGradient,
  forestGradient,
  goldenHourGradient,
  neonGradient,
  nordicGradient,
  pastelGradient,
  deepSpaceGradient,
} from 'css-magic-gradient'

element.style.background = sunsetGradient
ExportDescription
sunsetGradientOrange → magenta, bottom-right
oceanGradientCyan → dark navy, bottom
auroraGradientViolet → green → teal, right
fireGradientYellow → orange → red, top
midnightGradientDark indigo → near-black
peachGradientSoft pink → warm orange
mintGradientLight green → teal
rainbowGradientFull-spectrum conic (24 steps)
glowGradientRadial warm-gold glow
forestGradientLight green → deep forest green
goldenHourGradientWarm gold → pink → orange
neonGradientElectric green → vivid pink → bright cyan
nordicGradientIcy blue → cool gray → near-white
pastelGradientSoft lavender → blush pink → pale mint
deepSpaceGradientNear-black navy → deep indigo → violet

Color harmony generators

These use interpolateColors / createColorScale from color-value-tools for smooth perceptual transitions.

ts
import {
  createComplementaryGradient,
  createTriadicGradient,
  createAnalogousGradient,
  createTetradicGradient,
  createSplitComplementaryGradient,
  createMonochromaticGradient,
  createHueWheelGradient,
} from 'css-magic-gradient'

// Base color ↔ complement, interpolated in oklch (default)
createComplementaryGradient('#3498db', { steps: 7, interpolationSpace: 'oklch' })

// Triadic — 3 colors 120° apart; smoothness = total interpolated steps
createTriadicGradient('#e74c3c', { smoothness: 9, interpolationSpace: 'oklab' })

// Analogous — spread controls hue angle passed to analogous()
createAnalogousGradient('#2ecc71', { spread: 45, steps: 7 })

// Tetradic — 4 colors 90° apart; supports linear, radial, conic
createTetradicGradient('#9b59b6', { type: 'linear' })
createTetradicGradient('#9b59b6', { type: 'conic', steps: 24 })
createTetradicGradient('#9b59b6', { type: 'radial', interpolationSpace: 'oklch' })

// Split-complementary — base + two colors at 150° and 210°
createSplitComplementaryGradient('#3498db', { steps: 5 })

// Monochromatic shades via colorShades()
createMonochromaticGradient('#9b59b6', 7, { direction: 'to right' })

// Hue-wheel conic from any base color
createHueWheelGradient('#3498db', { steps: 16, fromAngle: 45 })

HarmonyGradientOptions

OptionTypeDefaultDescription
directionstring'to right'CSS direction keyword
anglenumberAngle in degrees
stepsnumber5Interpolation steps (3 = only anchor colors)
interpolationSpace'rgb' | 'hsl' | 'oklab' | 'oklch''oklch'Color space for JS-side interpolation

interpolationSpace vs interpolationinterpolationSpace controls how JavaScript mixes colors when building the stop list (via createColorScale / interpolateColors). interpolation adds in oklch to the CSS output and lets the browser interpolate between stops. Harmony generators produce pre-computed stop arrays, so only interpolationSpace applies to them.

'lab' and 'lch' are intentionally absent from interpolationSpacecreateColorScale does not support them. Use 'oklab' and 'oklch' instead (perceptually superior successors).

Palette generators

Generate gradients through tints, shades, or tones using Oklab-based interpolation from color-value-tools.

ts
import { createTintGradient, createShadeGradient, createToneGradient } from 'css-magic-gradient'

// Base color → white (through Oklab tints)
createTintGradient('#3498db', 7, { direction: 'to right' })

// Base color → black (through Oklab shades)
createShadeGradient('#e74c3c', 5)

// Base color → gray (through Oklab tones)
createToneGradient('#9b59b6', 7, { gray: '#707070' })
FunctionDescription
createTintGradient(color, steps?, opts?)Gradient from base color toward white
createShadeGradient(color, steps?, opts?)Gradient from base color toward black
createToneGradient(color, steps?, opts?)Gradient from base color toward gray. Accepts optional gray color