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-colorbackground-color
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 )
| Variable | Range | Weight | |
|---|---|---|---|
| Red | R | 0–255 | 21.26% |
| Green | G | 0–255 | 71.52% |
| Blue | B | 0–255 | 7.22% |
| Luma | Y | 0–255 |
Examples
Each color name uses the text color that luma selects.
| HTML Color | Hex | R | G | B | Y | Text |
|---|---|---|---|---|---|---|
| Black | #000000 | 0 | 0 | 0 | 0.00 | light |
| Blue | #0000FF | 0 | 0 | 255 | 18.41 | light |
| Red | #FF0000 | 255 | 0 | 0 | 54.21 | light |
| Gray | #7F7F7F | 127 | 127 | 127 | 127.00 | light |
| Gray | #808080 | 128 | 128 | 128 | 128.00 | dark |
| Green | #00FF00 | 0 | 255 | 0 | 182.38 | dark |
| White | #FFFFFF | 255 | 255 | 255 | 255.00 | dark |
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
| Feature | ITU Rec. 709 Luma | WCAG Relative Luminance | Oklab Lightness |
|---|---|---|---|
| Linearizes sRGB | No | Yes | Yes, then converts to Oklab |
| Output Range | 0–255 | 0–1 | 0–1 |
| Dark Text Cut-off | > 127.5 | > 0.179 | > 0.5 |
| Defined For | Video signals | Contrast ratios | Image 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.
| Hex | Luma Y | WCAG W | Oklab L |
|---|---|---|---|
| #636363 | 99.0light text | 0.1248light text | 0.500light text |
| #646464 | 100.0light text | 0.1274light text | 0.503dark text |
| #757575 | 117.0light text | 0.1779light text | 0.562dark text |
| #767676 | 118.0light text | 0.1812dark text | 0.566dark text |
| #7f7f7f | 127.0light text | 0.2122dark text | 0.597dark text |
| #808080 | 128.0dark text | 0.2159dark text | 0.600dark text |
Apple System Colors
Light appearance values from Apple’s Human Interface Guidelines (June 2025).
| Color | Luma Y | WCAG W | Oklab L |
|---|---|---|---|
| Blue#0088ff | 115.7light text | 0.2483dark text | 0.632dark text |
| Indigo#6155f5 | 99.1light text | 0.1563light text | 0.559dark text |
| Red#ff383c | 98.6light text | 0.2441dark text | 0.653dark text |
| Green#34c759 | 159.8dark text | 0.4230dark text | 0.730dark text |
References
- ITU-R Recommendation BT.709
- W3C WCAG 2.2: relative luminance
- W3C: Understanding Contrast (Minimum)
- Wikipedia: Luma
- Apple Developer: System-Defined Color Spaces
- Apple Human Interface Guidelines: Color
- W3C CSS Color 4: Oklab and OkLCh
- Lea Verou: On automatically generating contrasting text colors with CSS
- Björn Ottosson: A perceptual color space for image processing (Oklab)