dev.colors
make, convert, blend and adjust colors, and check text is readable on a background
Colors are strings in the hex form web pages use, "#rrggbb": two hex digits each for how much red, green and blue there is, from 00 to ff.
Every function here that takes a color also accepts a CSS name like “tomato”, the short form “#f80”, or a list of three numbers from 0 to 255.
Tags: conversion
colora color in “#rrggbb” form, from a CSS name, “#rgb”, “#rrggbb” or a list [r, g, b]rgbmake a color from red, green and blue amounts (0-255), or give one argument to get a color’s three amountshslmake a color from hue, saturation and lightness, or give one argument to get a color’s three valuesmixblend two colors, where t is how far to go from a toward b, 0 to 1lightenmake a color lighter, keeping its huedarkenmake a color darker, keeping its hueinvertfor a color, the opposite color on the color wheel, like white for blackgrayscalethe gray that looks as bright as the color doescontrasthow readable one color is on the other, as the WCAG contrast ratio from 1 (identical) to 21 (black on white)swatcha block of the color followed by its hex code, to preview it
Functions
Section titled “Functions”color(c: str|list) -> str
a color in “#rrggbb” form, from a CSS name, “#rgb”, “#rrggbb” or a list [r, g, b]
1color("tomato")"#ff6347"2color("#f80")"#ff8800"3color([255, 0, 128])"#ff0080"rgb(r: num, g: num, b: num) -> str / rgb(c: str|list) -> list
make a color from red, green and blue amounts (0-255), or give one argument to get a color’s three amounts
1rgb(255, 136, 0)"#ff8800"2"orange".rgb[255, 165, 0]hsl(h: num, s: num, l: num) -> str / hsl(c: str|list) -> list
make a color from hue, saturation and lightness, or give one argument to get a color’s three values
Hue is the position on the color wheel in degrees (0 red, 120 green, 240 blue), saturation how vivid it is and lightness how close to white, both from 0 to 100
1hsl(210, 80, 50)"#1980e6"2"teal".hsl[180, 100, 25]mix(a: str|list, b: str|list, t: num = 0.5) -> str
blend two colors, where t is how far to go from a toward b, 0 to 1
1mix("red", "blue")"#800080"2mix("white", "black", 25%)"#bfbfbf"lighten
Section titled “lighten”lighten(c: str|list, amount: num) -> str
make a color lighter, keeping its hue
amount, like 20%, is added to its HSL lightness
1lighten("#3478f6", 20%)"#96b9fa"darken
Section titled “darken”darken(c: str|list, amount: num) -> str
make a color darker, keeping its hue
amount, like 20%, is taken off its HSL lightness
1darken("#3478f6", 20%)"#0847bc"invert
Section titled “invert”invert(c: str|list) -> str
for a color, the opposite color on the color wheel, like white for black
1invert("navy")"#ffff7f"See also grayscale
grayscale
Section titled “grayscale”grayscale(c: str|list) -> str
the gray that looks as bright as the color does
1grayscale("tomato")"#969696"See also invert
contrast
Section titled “contrast”contrast(a: str|list, b: str|list) -> float
how readable one color is on the other, as the WCAG contrast ratio from 1 (identical) to 21 (black on white)
Body text needs 4.5 or more and large text 3
1contrast("white", "black")212contrast("#777", "white")4.48See also swatch
swatch
Section titled “swatch”swatch(c: str|list) -> str
a block of the color followed by its hex code, to preview it
Needs a terminal with full (24-bit) color
1swatch("tomato") #ff63472["red", "gold", "teal"].map(swatch).join(" ") #ff0000 #ffd700 #008080See also color
More examples
Section titled “More examples”colors
Section titled “colors”1# named to hex2color("rebeccapurple")"#663399"3# halfway between4mix("red", "blue")"#800080"5# a darker shade for a hovered button6darken("#3478f6", 10%)"#0a5aed"7# is white text readable on gray?8contrast("white", "#777")4.489# five hues evenly around the wheel10(0..5).map(|i| hsl(i * 72, 70, 50))["#d92626", "#b5d926", "#26d96e", "#266ed9", "#b526d9"]Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.