首页/AI 前端工程/better-colors
B

better-colors

by @jakubkrehelv
4.6(120)

该技能帮助前端开发者使用OKLCH颜色空间进行颜色转换、调色板生成、对比度检查和Tailwind v4主题集成。它将不直观的十六进制/RGB/HSL颜色转换为感知均匀的OKLCH值,自动处理色域边界、修复色调漂移,确保色彩在不同亮度下保持一致,提升可及性与设计质量。

oklchcolor-conversionpalette-generationcontrast-checkingtailwindGitHub
安装方式
npx skills add https://github.com/jakubkrehel/skills --skill better-colors
compare_arrows

Before / After 效果对比

1 组
使用前

在没有此技能之前,开发者手动调整颜色对比度时需要反复尝试不同色值,每次修改后使用在线工具验证,平均耗时30分钟才能达到AA标准。

使用后

此技能能够直接分析当前颜色对比度并给出建议的L值调整,开发者只需应用推荐值即可,整个过程缩短至2分钟。

SKILL.md

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
PalettesGenerate scales, multi-hue, dark modepalette-generation.md
ContrastAPCA/WCAG checks, fixing failing contrastaccessibility-contrast.md
Gamut & TailwindP3 fallbacks, @theme scales, gamut clampinggamut-and-tailwind.md

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.
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.35 when background L > 0.9
Lightness gap (dark bg)Foreground L > 0.9 when background L < 0.25
Hue drift threshold> 10° spread across palette steps = visible drift
APCA body text|Lc| >= 75 minimum, >= 90 preferred
APCA non-body text|Lc| >= 60 minimum
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: 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

用户评价 (0)

发表评价

效果
易用性
文档
兼容性

暂无评价

统计数据

安装量29.0K
评分4.6 / 5.0
版本
更新日期2026年10月13日
对比案例1 组

用户评分

4.6(120)
5
37%
4
43%
3
13%
2
5%
1
2%

为此 Skill 评分

0.0

兼容平台

🤖claude-code

时间线

创建2026年7月19日
最后更新2026年10月13日
🎁 Agent 知识卡片
调研问卷