Skip to main content
Color builds a color from one input form and converts it to any other. Construct it as a call or with new; both work. You cannot mix input forms in a single call.

Input forms

A Color takes exactly one of the following keys. The shape of the accepted argument is the ColorInput type.
{ hex: string }
A hex string such as "#2563eb".
{ rgb: [number, number, number] }
Red, green, and blue channels from 0 to 255.
{ rgba: [number, number, number, number] }
Red, green, and blue channels from 0 to 255, plus an alpha from 0 to 1.
{ hsl: [number, number, number] }
Hue, saturation, and lightness.
{ hsla: [number, number, number, number] }
Hue, saturation, and lightness, plus an alpha from 0 to 1.
Pass a single input form per Color. Mixing forms, for example { hex, rgb }, is not supported.

Conversions and operations

A Color converts to any output form and supports common color operations. The operations that return a color produce a new Color and leave the original unchanged.
string
Returns the color as a hex string.
string
Returns the color as a hex string including the alpha channel.
string
Returns an "rgb(...)" string.
string
Returns an "rgba(...)" string.
string
Returns an "hsl(...)" string.
string
Returns an "hsla(...)" string.
Color
Returns a new Color with the given alpha, from 0 to 1.
Color
Returns a new Color lightened by amount.
Color
Returns a new Color darkened by amount.
Color
Returns a new Color blended with other by ratio.
number
Returns the relative luminance of the color.
boolean
Returns whether the color reads as dark.

Using a Color anywhere a color is accepted

A Color is accepted anywhere a color is, so ColorLike = string | Color. Any color, background_color, or shape color field takes a hex string or a Color.
Because operations return a new Color, you can derive a whole palette from one base color with lighten, darken, alpha, and mix.
See the Reference for the full list of color related type exports, including ColorLike, ColorInput, and ColorValue.