CSS Magic Gradient
TypeScript library for generating CSS gradients — linear, radial, and conic. Includes gradient presets, color harmony generators, WCAG accessibility utilities, CSS variable support, canvas export, Vue 3 reactive hooks, and React hooks — with a single runtime dependency.
Features
createLinearGradient— linear (and repeating) gradients from a single base color or explicit color stops; accepts hex,rgb(),hsl(), named CSS colors, and CSS variables; CSS Color Level 4 interpolation within oklch / lab / hslcreateRadialGradient— radial gradients in auto-brightness, explicit stops, multi-layer, or color-harmony mode;circle/ellipse, custom size and positioncreateConicGradient— conic gradients with hue-rotation, color-scale, harmony, or explicit stops;createRainbowConicGradientfor a full-spectrum rainbow in one call- Color harmony generators —
createComplementaryGradient,createTriadicGradient,createAnalogousGradient,createTetradicGradient,createSplitComplementaryGradient— all backed bycolor-value-toolsfor perceptually uniform interpolation - Palette generators —
createTintGradient,createShadeGradient,createToneGradient— Oklab-based tints, shades, and tones - 15 gradient presets —
sunsetGradient,oceanGradient,auroraGradient, and 12 more ready-to-use gradient strings - Accessibility (WCAG) —
bestGradientTextColor,gradientContrastRatio(11-point sampling),gradientWcagLevel,createAccessibleGradient— auto-adjust stops to meet AA / AAA - CSS variable utilities —
extractGradientVariables,resolveGradientVariables - Canvas & image export —
gradientToCanvasGradient,gradientToImageData,gradientToDataURL; works with anyCanvasRenderingContext2Dor server-side canvas library - Vue 3 integration —
VueGradientPlugin+ 17 reactiveuse*hooks returningComputedRef<string>; SSR-safe; own entry point (css-magic-gradient/vue), never loaded unless imported - React integration — same 17 hooks in
css-magic-gradient/react; plainstringviauseMemo; no Vue dependency; SSR-safe - Full TypeScript — exported types for all options, return shapes, and discriminated unions
- Single runtime dependency —
color-value-toolsfor color math; Vue and React are optional peer deps, and neither is ever pulled in by the core entry point