relativeLuminance
Computes the WCAG 2.x relative luminance of a color: the perceived brightness from 0 (black) to 1 (white), after linearising the sRGB channels. The alpha channel is ignored: flatten a translucent color over its background first (see blendColors).
Available since v3.1.10
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
color | RgbColor | An sRGB color, channels 0-255 |
Returns
Section titled “Returns”number — The relative luminance, between 0 and 1
Examples
Section titled “Examples”Measure how bright a color is
Section titled “Measure how bright a color is”Black is 0, white is 1, and green weighs the most of the three primaries.
Pick light or dark text for a background
Section titled “Pick light or dark text for a background”A background brighter than about 0.18 takes dark text better than white text.
Related Types
Section titled “Related Types”RgbColor
Section titled “RgbColor”An RGB(A) color with channels expressed as plain numbers, convenient for further conversion or manipulation.
