What it does
color2k parses and manipulates sRGB colours in JavaScript. It handles common CSS inputs, including hex, RGB, HSL, named colours and transparency, and provides adjustment, interpolation and contrast functions. It is an open-source package released under MIT.
Lightness and saturation adjustments operate on HSL channels. For example, darkening by 0.1 subtracts ten percentage points of lightness; transparentize instead reduces the alpha channel. Both use decimal amounts between 0 and 1.
The output depends on the function. toHex returns hexadecimal text and includes alpha for a non-opaque colour; toRgba and toHsla return CSS strings. Parsing helpers return channel arrays. readableColor chooses black or white according to which has better contrast against the input.
A scale built with getScale takes a value from 0 to 1 and interpolates through its supplied colours. The library has no runtime dependencies and uses the MIT licence. Its sRGB focus excludes wide-gamut colour processing.
Strengths
- Parsing accepts several common CSS colour notations.
- Contrast helpers include a black-or-white foreground choice.
Watch out for
- Colour processing is limited to sRGB.
Best for
- JavaScript interfaces deriving colours and checking their contrast.
Sources
- 🌈 color2k (Oct 28, 2026)
- GitHub - ricokahler/color2k: a color parsing and manipulation lib served in roughly 2kB · GitHub (Oct 28, 2026)
- color2k/LICENSE at main · ricokahler/color2k · GitHub (Oct 28, 2026)
