This module provides basic types and functions for dealing with colors.
Colors can be constructed from HSL values, RGB values or Hex strings /
integers. In addition, a lot of standardized named colors can be found in
This module also provides functions to modify colors (e.g. lighten/darken, saturate/desaturate, complementary), to combine colors (mix) and to analyze colors (e.g. brightness, luminance, contrast).
Implementation detail: Colors are represented by their HSL values (hue, saturation, lightness) internally, as this provides more flexibility than storing RGB values. In particular, note that only colors within the sRGB gamut can be represented.
The representation of a color.
Eqinstance compares two
Colors by comparing their (integer) RGB values. This is different from comparing the HSL values (for example, HSL has many different representations of black (arbitrary hue and saturation values).
- Colors outside the sRGB gamut which cannot be displayed on a typical
computer screen can not be represented by
Color from XYZ coordinates in the CIE 1931 color space. Note
Color always represents a color in the sRGB gamut (colors that
can be represented on a typical computer screen) while the XYZ color space
is bigger. This function will tend to create fully saturated colors at the
edge of the sRGB gamut if the coordinates lie outside the sRGB range.
Color from lightness, chroma and hue coordinates in the CIE LCh
color space. This is a cylindrical transform of the Lab color space.
Note: See documentation for
xyz. The same restrictions apply here.
toHexString :: Color -> String
Return a hexadecimal representation of the color in the forms
aa refer to hexadecimal
digits corresponding to the RGBA channel values between
alpha channel is only represented when it has a value less than 100%.
The relative brightness of a color (normalized to 0.0 for darkest black and 1.0 for lightest white), according to the WCAG definition.
The contrast ratio of two colors. A minimum contrast ratio of 4.5 is
recommended to ensure that text is readable on a colored background. The
contrast ratio is symmetric on both arguments:
contrast c1 c2 == contrast c2 c1.