Oklch Skill

作者 jakubkrehel0e81f040e16d无许可证264 个星标收录于 2026年10月8日更新于 2026年10月8日仓库昨天更新

OKLCH color space for web projects. Convert hex/rgb/hsl to oklch, generate palettes, check contrast, handle gamut boundaries, and theme with Tailwind v4. Triggers on oklch, color conversion, palette generation, contrast ratio, gamut, display p3, design tokens, hue drift, chroma, dark mode colors.

仅含说明Design & Creative
AI 生成的概览

指导 CSS 中的 OKLCH 颜色工作:转换、调色板生成、对比度检查、色域处理与 Tailwind v4 主题化。

功能
该技能为在 Web 项目中使用 OKLCH 色彩空间提供参考指导。内容涵盖将 hex、rgb 和 hsl 值转换为 oklch、生成调色板色阶(包括多色相与深色模式变体)、检查 APCA 与 WCAG 对比度、处理 sRGB 与 P3 色域边界,以及使用 Tailwind v4 进行主题化。它还规定了审查输出格式,要求以修改前后对照的 Markdown 表格呈现颜色变更。
适用场景
适用于处理 oklch 值、转换现有颜色、构建或修复调色板色阶、诊断对比度不达标或色相偏移,以及迁移 Tailwind v4 主题令牌的场景。它面向 CSS 颜色决策,而非通用设计或编码工作。
运行要求
无需脚本或工具,仅为说明文档与参考文件。使用前提是熟悉 CSS 颜色语法,部分内容还需了解 Tailwind v4。

OKLCH Colors

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.

Quick Reference

CategoryWhen to useReference
ConversionHex/rgb/hsl to oklchcolor-conversion.md [blocked]
PalettesGenerate scales, multi-hue, dark modepalette-generation.md [blocked]
ContrastAPCA/WCAG checks, fixing failing contrastaccessibility-contrast.md [blocked]
Gamut & TailwindP3 fallbacks, @theme scales, gamut clampinggamut-and-tailwind.md [blocked]

Why OKLCH

  • Perceptual uniformity. Equal L steps = equal brightness. oklch(0.5 ...) is visually mid. HSL's lightness: 50% varies wildly by hue.
  • 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.

OKLCH Syntax

oklch(L C H)oklch(L C H / alpha)
ChannelRangeDescription
L (Lightness)0–10 = black, 1 = white. Perceptually uniform.
C (Chroma)0–~0.4Colorfulness. 0 = gray. Max depends on L and H.
H (Hue)0–360Hue angle in degrees.
alpha0–1Optional 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 -0 as 0. Browser support: Baseline 2023, 96%+ global coverage.

Key Thresholds

RuleValue
Light/dark boundaryL > 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 text4.5:1 AA, 7:1 AAA
Contrast fixAdjust L only — chroma has negligible effect

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.

BeforeAfter
color: #3b82f6color: oklch(0.623 0.188 259.815)
Same absolute C across huesSame C% of each hue's max chroma
No sRGB fallback for P3 color@media (color-gamut: p3) wrapper

This keeps feedback scannable and diff-friendly. Each row is a self-contained change the developer can act on independently.

Common Mistakes

IssueFix
Hex/rgb/hsl color in new codeConvert to oklch()
HSL palette ramp with hue driftRebuild 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 checkClamp to max chroma for the L/H in sRGB
Same absolute C across different huesUse same C% (percentage of max) for consistent vividness
P3 color without sRGB fallbackAdd @media (color-gamut: p3) pattern
Dark mode with hand-picked colorsDerive from light palette by reversing L mapping
Hex in Tailwind v4 @themeConvert to oklch values
Alpha with comma syntaxUse slash: oklch(L C H / alpha)

Reference Files

  • color-conversion.md [blocked] — Supported formats, conversion examples, bulk conversion rules, what to leave alone
  • palette-generation.md [blocked] — Scale convention, generation algorithm, multi-hue palettes, dark mode, why not HSL
  • accessibility-contrast.md [blocked] — APCA and WCAG 2 thresholds, fixing contrast with L, lightness gap guide, hue drift detection
  • gamut-and-tailwind.md [blocked] — sRGB vs P3, gamut clamping, CSS fallback patterns, Tailwind v4 @theme and migration

来源与署名

来源:jakubkrehel/oklch-skill位于skills/oklch-skill提交0e81f04

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架