Skip to content
ColorTokensKitby Penguin Design Ventures
Contents
Function

.getLCHString()

Log a color's lightness, chroma and hue in one short line, to check a color at a glance.

Updated View as Markdown

Log a color's lightness, chroma and hue as one short line with getLCHString(). It takes nothing and returns CIELab LCH as whole numbers, each rounded down:

swift
let brandColor = Color(hex: "#00B386")
print("Brand:", brandColor.getLCHString())   // Brand: L:64 C:50 H:166

Color(hex: "#3C80C4").getLCHString()         // "L:52 C:41 H:271"

Reading the numbers#

  • L is CIELab L*, from 0 (black) to 100 (white). It's the lightness WCAG contrast depends on, so two colors with the same L have about the same contrast on white.
  • C is chroma, how far the color is from gray.
  • H is the hue in degrees, around the CIELab wheel.

For the exact numbers, use .toLCH(), which keeps the decimals.

How it behaves#

Each number is cut to a whole number, not rounded, so 64.93 becomes 64. The numbers are CIELab LCH with the D65 white point, not OKLCH, so the hue differs from the one the palette uses: #00B386 is at 166° here and at 166.99° in OKLCH.

A color beyond sRGB comes through without clamping, so a Display P3 color can show more chroma than an sRGB color can reach. A token gives its light-mode value on iOS 17, macOS 14 and later.

API#

swift
public extension Color {
    func getLCHString() -> String   // "L:64 C:50 H:166"
}

It takes no parameters and returns "L:… C:… H:…" with each number rounded down to a whole number.

Sources#

See also

  • .toLCH() Read a color as CIELab lightness, chroma and hue, to match LCH numbers or check contrast.
  • .getHexString() Log a color or hand it to a design tool as an sRGB hex string, with alpha when it's translucent.
  • .toOKLCH() Read a color's lightness, chroma and hue the way the palette sees them, to compare or adjust it.
  • How accessible is it? What the palette guarantees for contrast in every hue and mode, and what you still need to check.