Luma: Apple & Perceived Brightness

Apple uses luma (perceived brightness) to set text color based on background color. Apple divides the full luma range into equal halves, providing a simple and consistent decision boundary.

When Safari uses a webpage background-color to color browser UI, it also calculates the background-color luma to set browser UI text color:

luma ≤ 127.5Background is dark: Safari uses light text
luma > 127.5Background is light: Safari uses dark text

Try it in the Safari Color Tinting demo.

Luma

Rec. 709 (ITU Recommendation BT.709) is the international standard for HDTV. It defines how to calculate luma from the red, green and blue values of a color.

Luma is a weighted sum of gamma-encoded RGB values. In video, it represents the brightness of an image: its black-and-white part. Luma is not the same as relative luminance, which applies weights to linear RGB values, and it does not exactly represent the luminance of an image (Wikipedia: Luma). Of the three Rec. 709 weights, green is the largest and blue is the smallest.

Luma Formula

Y = ( 0.2126 × R ) + ( 0.7152 × G ) + ( 0.0722 × B )
VariableRangeWeight
RedR0–25521.26%
GreenG0–25571.52%
BlueB0–2557.22%
LumaY0–255

Examples

Each color name uses the text color that luma selects.

HTML ColorHexRGBYText
Black#0000000000.00light
Blue#0000FF0025518.41light
Red#FF00002550054.21light
Gray#7F7F7F127127127127.00light
Gray#808080128128128128.00dark
Green#00FF0002550182.38dark
White#FFFFFF255255255255.00dark

Implementation Example

function selectThemeWithLuma(bgColor) {
  // remove leading #
  let hex = bgColor.replace(/^#/, '');

  // parse RGB components from hex
  const r = parseInt(hex.substring(0, 2), 16);
  const g = parseInt(hex.substring(2, 4), 16);
  const b = parseInt(hex.substring(4, 6), 16);

  // calculate Rec. 709 Luma using standard coefficients
  const Y = 0.2126 * r + 0.7152 * g + 0.0722 * b;

  // threshold at midpoint: 127.5
  // Y ≤ 127.5 = dark background, use light text
  // Y > 127.5 = light background, use dark text
  return Y <= 127.5;
}

Alternatives

WCAG Relative Luminance

W3C Web Content Accessibility Guidelines (WCAG) define relative luminance from 0 (black) to 1 (white), using the Rec. 709 weights on linearized sRGB values. At level AA, the contrast ratio between text and background must be at least 4.5:1, or 3:1 for large text (18 pt, or 14 pt bold). Above a relative luminance of about 0.179, black text has a higher ratio than white text (Lea Verou, an editor of W3C’s CSS Color specifications).

Oklab Lightness

Oklab, by Björn Ottosson, is designed to predict perceived lightness, chroma and hue. Its L is perceived lightness on a scale from 0 to 1, with 0.5 at the midpoint.

Comparison

FeatureITU Rec. 709
Luma
WCAG
Relative Luminance
Oklab
Lightness
Linearizes sRGBNoYesYes, then converts to Oklab
Output Range0–2550–10–1
Dark Text Cut-off> 127.5> 0.179> 0.5
Defined ForVideo signalsContrast ratiosImage processing

Luma vs. WCAG vs. Oklab

Each cell uses the text color that its method selects.

Gray Steps

Three pairs of grays, each one RGB step apart.

HexLuma YWCAG WOklab L
#63636399.0light text0.1248light text0.500light text
#646464100.0light text0.1274light text0.503dark text
#757575117.0light text0.1779light text0.562dark text
#767676118.0light text0.1812dark text0.566dark text
#7f7f7f127.0light text0.2122dark text0.597dark text
#808080128.0dark text0.2159dark text0.600dark text

Apple System Colors

Light appearance values from Apple’s Human Interface Guidelines (June 2025).

ColorLuma YWCAG WOklab L
Blue#0088ff115.7light text0.2483dark text0.632dark text
Indigo#6155f599.1light text0.1563light text0.559dark text
Red#ff383c98.6light text0.2441dark text0.653dark text
Green#34c759159.8dark text0.4230dark text0.730dark text
Compare Web-Safe Colors

References