miniBill/elm-oklch/1.1.0

Color.Oklch

Types

type alias Oklch =
{ lightness : Float
, chroma : Float
, hue : Float
, alpha : Float
}

A color in the Oklch space.

  • lightness ranges from 0.0 to 1.0 (inclusive),
  • chroma ranges from 0.0 to approximatively 0.37 (inclusive),
  • hue ranges from 0.0 to 1.0 (inclusive),
  • alpha ranges from 0.0 to 1.0 (inclusive).

Creating colors

oklch : Float -> Float -> Float -> Oklch

Builds a color from its lightness, chroma and hue components.

  • lightness ranges from 0.0 to 1.0 (inclusive),
  • chroma ranges from 0.0 to approximatively 0.37 (inclusive),
  • hue ranges from 0.0 to 1.0 (inclusive),
  • alpha ranges from 0.0 to 1.0.
oklcha : Float -> Float -> Float -> Float -> Oklch

Builds a color from its lightness, chroma, hue and alpha components.

  • lightness ranges from 0.0 to 1.0 (inclusive),
  • chroma ranges from 0.0 to approximatively 0.37 (inclusive),
  • hue ranges from 0.0 to 1.0 (inclusive),
  • alpha ranges from 0.0 to 1.0.

Conversions

fromColor : Color -> Oklch

Convert a color from Color (sRGB) to Oklch.

toColor : Oklch -> Color

Convert a color from Oklch to Color (sRGB).

fromOklab : Oklab -> Oklch

Convert from Oklab to Oklch.

toOklab : Oklch -> Oklab

Convert from Oklch to Oklab.

toCssString : Oklch -> String

Converts a color to a string suitable for use in CSS.

Html.Attributes.style "background-color" (Color.Oklch.toCssString (Color.Oklch.oklch 0.5 0.2 0.5))

Note: the current implementation produces a string in the form oklch(l% c h), but this may change in the future, and you should not rely on this implementation detail.