Contrast Ratios (WCAG)
| Level | Normal Text | Large Text (≥18pt or ≥14pt bold) | UI Components |
|---|
| AA (minimum) | ≥ 4.5:1 | ≥ 3:1 | ≥ 3:1 |
| AAA (enhanced) |
≥ 7:1 | ≥ 4.5:1 | — |
Critical thresholds on white background:
- -
#767676 → 4.54:1 ✅ barely passes - INLINECODE1 → 4.47:1 ❌ fails (cannot round up)
- INLINECODE2 → 4.6:1 ✅ safe minimum gray
Pure colors on white:
- - Red
#FF0000 → 4:1 ❌ fails for normal text - Green
#00FF00 → 1.4:1 ❌ always fails (never use for text) - Blue
#0000FF → 8.6:1 ✅ passes AAA
Color-Only Information
Never rely on color alone to convey meaning. 8% of men have color vision deficiency.
CODEBLOCK0
Test designs in grayscale to verify information is still distinguishable.
Semantic Color Tokens
Three-layer architecture for maintainable palettes:
CODEBLOCK1
Name tokens by function, not appearance: text-primary not text-blue.
Dark Mode
Create depth with luminosity, not shadows:
CODEBLOCK2
Avoid pure black #000 and pure white #FFF as backgrounds. Use #0a0a0a and #fafafa to reduce eye strain.
Neutral Grays
Add a subtle tint of your primary color to grays for cohesion:
CODEBLOCK3
This creates a more polished, intentional palette.
HSL for Variations
HSL makes generating consistent color scales trivial:
CODEBLOCK4
Same hue and saturation, only lightness changes.
Balance Rule
60-30-10 distribution:
- - 60% dominant (backgrounds, containers)
- 30% secondary (cards, sections)
- 10% accent (CTAs, highlights)
Limit palette to 3-5 colors plus neutrals. More creates visual noise.
Common Mistakes
- -
text-gray-400 or lighter on white background typically fails contrast - Primary/accent colors for body text cause eye fatigue—use for headings and CTAs only
- Hover states that only change opacity may fail contrast—change hue or lightness
- Purple-to-blue gradients are an AI cliché—choose intentional combinations
- Testing only light mode—dark mode often reveals contrast issues
- Red/green as only differentiator—use icons or text labels alongside
Safe Combinations
| Sector | Primary | Secondary | Why |
|---|
| Fintech | Navy #00246B | Light Blue #CADCFC | Trust + clarity |
| Healthcare |
Light Blue #89ABE3 | White | Calm + clean |
| E-commerce | Red #F96167 | Yellow #F9E795 | Urgency + optimism |
Avoid: red + green (colorblindness), adjacent hues (blue + purple), yellow + white (no contrast).
对比度比率(WCAG)
| 级别 | 常规文本 | 大号文本(≥18pt 或 ≥14pt 粗体) | UI 组件 |
|---|
| AA(最低标准) | ≥ 4.5:1 | ≥ 3:1 | ≥ 3:1 |
| AAA(增强标准) |
≥ 7:1 | ≥ 4.5:1 | — |
白色背景上的关键阈值:
- - #767676 → 4.54:1 ✅ 勉强通过
- #777777 → 4.47:1 ❌ 未通过(不可四舍五入)
- #757575 → 4.6:1 ✅ 安全最低灰度
白色背景上的纯色:
- - 红色 #FF0000 → 4:1 ❌ 常规文本未通过
- 绿色 #00FF00 → 1.4:1 ❌ 始终未通过(切勿用于文本)
- 蓝色 #0000FF → 8.6:1 ✅ 通过 AAA 标准
仅靠颜色传达信息
切勿仅依靠颜色来传达含义。8% 的男性存在色觉缺陷。
html
活跃
非活跃
✓ 活跃
✗ 非活跃
在灰度模式下测试设计,确保信息仍可区分。
语义化颜色令牌
三层架构实现可维护的调色板:
css
/ 第一层:基础色(原始值) /
--blue-500: #3B82F6;
--gray-900: #111827;
/ 第二层:语义色(角色) /
--color-primary: var(--blue-500);
--color-text: var(--gray-900);
--color-error: var(--red-500);
/ 第三层:组件色(特定用途) /
--btn-primary-bg: var(--color-primary);
--input-border-error: var(--color-error);
按功能而非外观命名令牌:使用 text-primary 而非 text-blue。
深色模式
通过亮度而非阴影来营造层次感:
css
/ 浅色模式使用阴影表现层次 /
/ 深色模式使用表面亮度 /
--surface-0: hsl(220 15% 8%); / 页面背景 /
--surface-1: hsl(220 15% 12%); / 卡片 /
--surface-2: hsl(220 15% 16%); / 提升元素 /
--surface-3: hsl(220 15% 20%); / 弹窗 /
避免使用纯黑 #000 和纯白 #FFF 作为背景。使用 #0a0a0a 和 #fafafa 以减少视觉疲劳。
中性灰色
在灰色中加入主色的微妙色调以增强整体感:
css
/ 替代纯灰色 /
--gray-100: hsl(220 10% 96%); / 轻微蓝色调 /
--gray-500: hsl(220 10% 46%);
--gray-900: hsl(220 10% 10%);
这样可以创建更精致、更有意境的调色板。
使用 HSL 生成变体
HSL 让生成一致的色阶变得简单:
css
--primary-100: hsl(220 90% 95%);
--primary-300: hsl(220 90% 75%);
--primary-500: hsl(220 90% 55%);
--primary-700: hsl(220 90% 35%);
--primary-900: hsl(220 90% 15%);
相同的色相和饱和度,仅亮度变化。
平衡法则
60-30-10 分布:
- - 60% 主色调(背景、容器)
- 30% 次要色(卡片、区块)
- 10% 强调色(行动号召、高亮)
调色板限制在 3-5 种颜色加上中性色。更多颜色会造成视觉杂乱。
常见错误
- - text-gray-400 或更浅的颜色在白色背景上通常无法通过对比度测试
- 主色/强调色用于正文文本会导致视觉疲劳——仅用于标题和行动号召
- 仅改变透明度的悬停状态可能无法通过对比度测试——应改变色相或亮度
- 紫色到蓝色的渐变是 AI 的常见套路——选择有意的组合
- 仅测试浅色模式——深色模式常会暴露对比度问题
- 仅用红/绿作为区分手段——应同时使用图标或文本标签
安全配色组合
| 领域 | 主色 | 次要色 | 原因 |
|---|
| 金融科技 | 海军蓝 #00246B | 浅蓝 #CADCFC | 信任 + 清晰 |
| 医疗健康 |
浅蓝 #89ABE3 | 白色 | 平静 + 整洁 |
| 电子商务 | 红色 #F96167 | 黄色 #F9E795 | 紧迫 + 乐观 |
避免:红 + 绿(色盲问题)、相邻色相(蓝 + 紫)、黄 + 白(无对比度)。