What it does
tinygradient is an MIT-licensed JavaScript library built with TinyColor. It supports positioned colour stops, RGB or HSV interpolation, stepped colour results and CSS gradient strings for web backgrounds.
Place colour stops anywhere from 0 to 1, or leave their positions unset for equal spacing. A stop with a position but no colour shifts the midpoint between its neighbours. This is useful when a transition should stay dark for longer before reaching its light endpoint.
Install with npm install tinygradient. Call rgb(n) or hsv(n) for a stepped sequence. HSV blending follows the colour wheel clockwise, counter-clockwise, by the shorter arc or by the longer arc. Results are TinyColor objects. The css() method instead returns a linear or radial gradient string, and rgbAt() or hsvAt() samples one position.
Some sequences contain one extra step, so check the returned length. TinyColor is a dependency. MIT permits commercial use with the required copyright and permission notices retained.
Strengths
- A position-only stop can move the midpoint without adding another colour.
- Gradients can be reversed or looped into new instances.
Watch out for
- The returned sequence can have an extra step in some conditions.
- The library depends on TinyColor.
Best for
- JavaScript projects needing precise control over multi-stop gradient transitions.