better-colors
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOKLCH Colors
OKLCH 色彩
OKLCH is a perceptually uniform color space where the numbers actually mean what you think they mean. Most color problems in CSS — broken palettes, failing contrast, hue drift — come from using color spaces that don't match how we see. OKLCH fixes the model so the tools work. To explore interactively, visit oklch.fyi.
OKLCH 是一种感知均匀的色彩空间,其中的数值与你直观理解的含义一致。CSS 中的大多数色彩问题——调色板混乱、对比度不达标、色相偏移——都源于使用不符合人类视觉感知的色彩空间。OKLCH 修复了这一模型,让相关工具能够正常发挥作用。如需交互式探索,请访问 oklch.fyi。
Quick Reference
快速参考
| Category | When to use | Reference |
|---|---|---|
| Conversion | Hex/rgb/hsl to oklch | color-conversion.md |
| Palettes | Generate scales, multi-hue, dark mode | palette-generation.md |
| Contrast | APCA/WCAG checks, fixing failing contrast | accessibility-contrast.md |
| Gamut & Tailwind | P3 fallbacks, | gamut-and-tailwind.md |
| 类别 | 适用场景 | 参考文档 |
|---|---|---|
| 色彩转换 | 将hex/rgb/hsl转换为oklch | color-conversion.md |
| 调色板 | 生成色彩刻度、多色相调色板、深色模式配色 | palette-generation.md |
| 对比度 | APCA/WCAG 检查、修复不达标对比度 | accessibility-contrast.md |
| 色域与Tailwind | P3 降级方案、 | gamut-and-tailwind.md |
Why OKLCH
为什么选择OKLCH
- Perceptual uniformity. Equal L steps = equal brightness. is visually mid. HSL's
oklch(0.5 ...)varies wildly by hue.lightness: 50% - Stable hue. HSL blue shifts toward purple as lightness changes. OKLCH hue stays constant across the full lightness range.
- Independent chroma. Chroma is an absolute measure of colorfulness that doesn't depend on lightness. HSL saturation does.
- Finite gamut. Not every oklch value maps to a displayable sRGB color. High-chroma values at certain hues will clip — gamut awareness is required.
- 感知均匀性:相同的L值增量对应相同的视觉亮度变化。在视觉上是中间亮度。而HSL的
oklch(0.5 ...)在不同色相下视觉亮度差异极大。lightness: 50% - 色相稳定:HSL中的蓝色会随着亮度变化向紫色偏移。OKLCH的色相在整个亮度范围内保持恒定。
- 独立色度:色度(Chroma)是色彩鲜艳度的绝对衡量标准,与亮度无关。而HSL的饱和度则依赖于亮度。
- 有限色域:并非所有oklch值都能映射为可显示的sRGB色彩。特定色相下的高色度值会被截断——因此需要具备色域意识。
OKLCH Syntax
OKLCH 语法
oklch(L C H)
oklch(L C H / alpha)| Channel | Range | Description |
|---|---|---|
| L (Lightness) | 0–1 | 0 = black, 1 = white. Perceptually uniform. |
| C (Chroma) | 0–~0.4 | Colorfulness. 0 = gray. Max depends on L and H. |
| H (Hue) | 0–360 | Hue angle in degrees. |
| alpha | 0–1 | Optional transparency. Slash syntax. |
css
oklch(0.637 0.237 25.331)
oklch(0.8 0.05 200 / 0.5)Formatting: L and C use 3 decimal places, H uses up to 3. Drop trailing zeros. Format as . Browser support: Baseline 2023, 96%+ global coverage.
-00oklch(L C H)
oklch(L C H / alpha)| 通道 | 范围 | 说明 |
|---|---|---|
| L(亮度) | 0–1 | 0 = 黑色,1 = 白色,感知均匀。 |
| C(色度) | 0–~0.4 | 色彩鲜艳度。0 = 灰色。最大值取决于L和H。 |
| H(色相) | 0–360 | 色相角度(度数)。 |
| alpha | 0–1 | 可选透明度,使用斜杠语法。 |
css
oklch(0.637 0.237 25.331)
oklch(0.8 0.05 200 / 0.5)格式规范:L和C保留3位小数,H最多保留3位小数。去除末尾的零。将格式化为。浏览器支持:2023基线标准,全球覆盖率96%以上。
-00Key Thresholds
关键阈值
| Rule | Value |
|---|---|
| Light/dark boundary | L > 0.6 = light background → use dark text |
| Lightness gap (light bg) | Foreground L < 0.45 when background L > 0.85 |
| Lightness gap (dark bg) | Foreground L > 0.75 when background L < 0.25 |
| Hue drift threshold | > 10° spread across palette steps = visible drift |
| APCA normal text | |Lc| >= 60 to pass, >= 75 for pass+ |
| WCAG 2 normal text | 4.5:1 AA, 7:1 AAA |
| Contrast fix | Adjust L only — chroma has negligible effect |
| 规则 | 数值 |
|---|---|
| 明暗边界 | L > 0.6 = 浅色背景 → 使用深色文本 |
| 亮度差(浅色背景) | 当背景L > 0.85时,前景L < 0.45 |
| 亮度差(深色背景) | 当背景L < 0.25时,前景L > 0.75 |
| 色相偏移阈值 | 调色板刻度间色相差异>10° = 可见偏移 |
| APCA 普通文本 | |Lc| >= 60 为达标,>= 75 为优秀 |
| WCAG 2 普通文本 | 4.5:1 AA级,7:1 AAA级 |
| 对比度修复 | 仅调整L通道——色度的影响可忽略不计 |
Review Output Format
输出格式规范
Always present color changes as a markdown table with Before and After columns. Include every color that was changed — not just a subset. Never list findings as separate "Before:" / "After:" lines outside of a table.
| Before | After |
|---|---|
| |
| Same absolute C across hues | Same C% of each hue's max chroma |
| No sRGB fallback for P3 color | |
This keeps feedback scannable and diff-friendly. Each row is a self-contained change the developer can act on independently.
始终以Markdown表格形式呈现色彩变更,包含Before和After列。需包含所有变更的色彩——而非仅子集。切勿将结果以独立的"Before:" / "After:"行形式列出表格之外。
| Before | After |
|---|---|
| |
| 不同色相使用相同绝对C值 | 为每个色相使用相同比例的最大色度 |
| P3色彩未提供sRGB降级方案 | 添加 |
这种格式让反馈易于扫描且便于对比差异。每一行都是开发者可独立执行的完整变更操作。
Common Mistakes
常见错误
| Issue | Fix |
|---|---|
| Hex/rgb/hsl color in new code | Convert to |
| HSL palette ramp with hue drift | Rebuild with constant oklch hue |
| Failing contrast (check foreground vs its background using APCA) | Adjust oklch L channel, keep C and H |
| High chroma without gamut check | Clamp to max chroma for the L/H in sRGB |
| Same absolute C across different hues | Use same C% (percentage of max) for consistent vividness |
| P3 color without sRGB fallback | Add |
| Dark mode with hand-picked colors | Derive from light palette by reversing L mapping |
Hex in Tailwind v4 | Convert to oklch values |
| Alpha with comma syntax | Use slash: |
| 问题 | 修复方案 |
|---|---|
| 新代码中使用hex/rgb/hsl色彩 | 转换为 |
| HSL调色板刻度存在色相偏移 | 使用恒定的oklch色相重新构建 |
| 对比度不达标(使用APCA检查前景与背景) | 调整oklch的L通道,保持C和H不变 |
| 高色度未做色域检查 | 将其限制为对应L/H在sRGB中的最大色度 |
| 不同色相使用相同绝对C值 | 使用相同比例的最大色度以保证鲜艳度一致 |
| P3色彩未提供sRGB降级方案 | 添加 |
| 手动挑选深色模式色彩 | 通过反转L值映射从浅色调色板推导 |
Tailwind v4 | 转换为oklch值 |
| 使用逗号语法设置透明度 | 使用斜杠语法: |
Reference Files
参考文档
- color-conversion.md — Supported formats, conversion examples, bulk conversion rules, what to leave alone
- palette-generation.md — Scale convention, generation algorithm, multi-hue palettes, dark mode, why not HSL
- accessibility-contrast.md — APCA and WCAG 2 thresholds, fixing contrast with L, lightness gap guide, hue drift detection
- gamut-and-tailwind.md — sRGB vs P3, gamut clamping, CSS fallback patterns, Tailwind v4 @theme and migration
- color-conversion.md — 支持的格式、转换示例、批量转换规则、无需修改的内容
- palette-generation.md — 刻度约定、生成算法、多色相调色板、深色模式、为何不使用HSL
- accessibility-contrast.md — APCA与WCAG 2阈值、通过调整L修复对比度、亮度差指南、色相偏移检测
- gamut-and-tailwind.md — sRGB vs P3、色域限制、CSS降级方案、Tailwind v4 @theme与迁移