Skip to content

Color type

Color type is used in Iconify Utils in functions for parsing colors.

You can find this type in src/colors/types.ts of Iconify Utils source code.

Type is an object, with type property showing what color type it is, then optional properties for that type.

Browsers support various complex colors, which can contain CSS variables, functions. Iconify Utils parser is very basic, it supports only commonly used namespaces that have been supported by all browsers for many years.

RGB

RGB color, usually converted from hexadecimal color like "#ff8080", color keyword "red" or RGBA color like "rgba(255, 128, 128, 0.5)".

It has the following properties:

  • type = "rgb".
  • r, g, b red, green and blue color components (0 - 255).
  • alpha alpha (0 - 1).

HSL

HSL color, usually converted from HSL or HSLA color like "hsla(90, 50%, 50%, 0.5)".

It has the following properties:

  • type = "hsl".
  • h hue that can be any number, but usually is in 0 - 360 range.
  • s, l saturation and lightness components (0 - 100).
  • alpha alpha (0 - 1).

LAB

Lab color, currently being implemented by browsers, is converted from color strings like "lab(50% 50 50 / 1)".

It has the following properties:

  • type = "lab".
  • l lightness (0 - 100).
  • a, b are distances along a and b axis in Lab color space.
  • alpha alpha (0 - 1).

LCH

LCH color, currently being implemented by browsers, is converted from color strings like "lch(50% 50 50 / 1)".

It has the following properties:

  • type = "lab".
  • l lightness (0 - 100).
  • c chroma, usually in 0 - 230 range, but it can be higher.
  • h hue angle.
  • alpha alpha (0 - 1).

Keywords

Several keywords have their own types that represent special colors.

They exist because functions for parsing colors can be used for cleaning up and parsing various icons, where finding values like "currentColor" and "none" could be important.

transparent

Transparent color has a special type with only one property:

  • type = "transparent".

When converting transparent colors like "rgba(0, 0, 0, 0)", conversion function will return transparent type, making it easier to compare various colors.

none

"none" also has a special type with only one property:

  • type = "none".

currentColor

"currentColor" also has a special type with only one property:

  • type = "current".

Other colors

This type is meant for parsing basic colors in SVG, not full color parsing, so it is limited only to simple colors and keywords that are important when parsing icons.

Released under the Apache 2.0 License.