jon/color-tools is a color toolkit for Clojure and ClojureScript.
Clojure apps often need format conversion, palette generation, contrast checks,
and theme tokens. jon/color-tools puts those operations in one namespace.
The library follows these core principles:
Every function is pure: it takes colors and returns new colors without side effects.
The same API runs in Clojure (JVM) and ClojureScript (browser and Node.js).
Functions accept colors in multiple formats, including hex strings and RGB vectors, and return the same shape when the operation can preserve it.
One namespace covers format conversions, color theory, accessibility, blending, gradients, and theme tokens.
The library supports several color formats:
"#ff5733" or "#f53"[255, 87, 51] with values 0-255[255, 87, 51, 0.8] with alpha 0-1"rgb(255, 87, 51)" or "rgb(255 87 51)""rgba(255, 87, 51, 0.8)" or "rgba(255 87 51 0.8)"[9, 100, 60] (Hue 0-360, Saturation/Lightness 0-100)[9, 80, 100] (Hue 0-360, Saturation/Value 0-100)Most manipulation functions preserve the input format:
(lighten "#ff5733" 0.2) ; Returns hex string
;=> "#ffac99"
(lighten [255 87 51] 0.2) ; Returns RGB vector
;=> [255 172 153]
The library implements color theory concepts like:
Built-in support for WCAG (Web Content Accessibility Guidelines) compliance:
Require the namespace and call the functions:
(require '[jon.color-tools :as color])
;; Convert formats
(color/->rgb "#3498db") ; hex to RGB
;=> [52 152 219]
(color/->rgb "rgb(52, 152, 219)") ; CSS string to RGB
;=> [52 152 219]
(color/->hex [52 152 219]) ; RGB to hex
;=> "#3498db"
;; Manipulate colors
(color/lighten "#3498db" 0.2) ; hex input
;=> "#8ac4ea"
(color/lighten "rgb(52, 152, 219)" 0.2) ; CSS string input
;=> "#8ac4ea"
;; Generate palettes
(color/analogous "#3498db" 3)
;=> ["#3344db" "#7633db" "#ca33db"]
;; Check accessibility
(color/accessible? "#3498db" "#ffffff")
;=> false ; Doesn't meet AA standards
(color/contrast-ratio "#3498db" "#ffffff")
;=> 3.15 ; Needs 4.5 for AA
;; Generate app-ready accessible theme tokens
(def theme (color/accessible-theme "#3498db" {:mode :light :level :aa}))
(:on-primary theme)
;=> "#000000"
(color/theme->css-vars theme)
;=> {"--ct-primary" "#3498db", "--ct-on-primary" "#000000", ...}
The namespace groups functions by task:
Validate color formats and normalize values, such as expanding 3-digit hex codes.
Convert between supported color formats.
Modify colors with lighten, darken, saturate, adjust-hue, invert,
and related functions.
Analyze brightness, warmth, vibrancy, and related properties.
Generate color harmonies and palette variants.
Check WCAG contrast and find accessible alternatives.
Generate accessible UI theme tokens and export CSS custom properties.
Combine colors with mixing, blending, and alpha compositing.
The implementation keeps runtime overhead low:
For examples and installation notes, see README.md.
For design system, accessibility, and lighting workflows, see the workflow guide. The test suite has more examples.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |