工具箱Toolbox/颜色转换Colour Converter

颜色转换Colour Converter

HEX、RGB、HSL、CMYK 四种写法任意一种输进来,其余三种自动给出,顺带算对比度。 Type any of HEX, RGB, HSL or CMYK; the other three follow, with contrast ratios alongside.

与文字颜色的对比度(WCAG 2.1)Contrast against text (WCAG 2.1)
文字Text 对比度Ratio 正文 AA (4.5)Body AA (4.5) 大字 AA (3)Large AA (3)

对比度 4.5:1 是正文的及格线,3:1 适配合格字号 ≥24px 或粗体 ≥19px 的大字;AAA 要求 7:1。 4.5:1 is the pass mark for body text; 3:1 applies to large text (≥24px, or ≥19px bold). AAA asks for 7:1.

明暗色阶(点一下就能取用)Tints and shades (click to use)

三种写法,三种用途Three notations, three jobs

HEX 是给机器看的十六进制,六个字符两位一组,紧凑、好复制,设计稿和 CSS 里最常见,但它对人没有意义——#2f6fed 看不出有多蓝。RGB 拆成三个 0–255 的分量,直观一些,做透明度、用 rgba() 叠加时离不开。HSL 换成色相、饱和度、亮度:色相是 0–360 度的色轮角度,饱和度和亮度是百分比。调一个品牌色的浅色版本时,HSL 只要抬亮度;HEX 就得重新算三个十六进制位,这正是它存在的理由。 HEX is the machine-facing hexadecimal form: six characters, two per channel, compact and easy to copy — the default in design files and CSS, but meaningless to humans (#2f6fed tells you nothing about how blue it is). RGB splits it into three 0–255 channels, more legible, and indispensable for alpha work with rgba(). HSL re-expresses the colour as hue, saturation and lightness: hue is an angle on the 0–360 colour wheel, the other two are percentages. To make a lighter brand tint, HSL only needs the lightness raised; HEX would need three hex digits recomputed. That is the whole reason it exists.

CMYK 为什么算不准Why CMYK here is approximate

屏幕是发光的 RGB,印刷是吸光的 CMYK,两者之间没有唯一的换算公式——结果取决于纸张、油墨和印刷机的色彩特性(ICC 配置文件)。本工具给的是「朴素换算」,只保证四色加起来是合理的,不能直接拿去制版。真正印东西请让设计软件用目标印刷厂的 ICC 配置文件转换。 Screens emit light in RGB; print absorbs it in CMYK, and there is no single formula between them — the result depends on paper, ink and press, described by an ICC profile. The conversion here is the naive one: the four values add up sensibly, but it is not press-ready. For real printing, let design software convert through the printer's ICC profile.

对比度不只看「深不深」Contrast isn't just darkness

WCAG 的对比度用的是相对亮度,不是人眼感觉的明度。计算时先把每个通道做伽马校正(线性化),再按 0.2126、0.7152、0.0722 加权——绿色对亮度的贡献最大,蓝色最小。所以同样饱和的蓝色和黄色,黄色在深色背景上看着更刺眼,算出来的对比度也更高。这也是为什么纯蓝文字配白底经常不达标:#0000ff 对白色的对比度只有 8.6:1,看着却很难受,因为蓝色通道在人眼里的权重最低,锐度也最差。 WCAG contrast uses relative luminance, not perceived brightness. Each channel is linearised (gamma-corrected), then weighted 0.2126 / 0.7152 / 0.0722 — green contributes most to luminance, blue least. That's why equally saturated blue and yellow feel so different: yellow glares on dark backgrounds and also scores higher. It's also why pure blue on white often disappoints — #0000ff on white is only 8.6:1 and still reads poorly, because the blue channel carries the least weight and the eye focuses it worst.

常见问题FAQ

支持 8 位带透明度的 HEX 吗(#RRGGBBAA)?Does it accept 8-digit HEX (#RRGGBBAA)?

输入时会读取 RGB 部分并忽略 alpha,因为输出表格只处理不透明颜色。需要透明度请直接用 rgba() 或 #RRGGBBAA 写进 CSS,浏览器都支持。 The RGB part is read and alpha ignored, since the output table only handles opaque colours. For transparency, write rgba() or #RRGGBBAA directly in CSS — every browser supports it.

为什么 HSL 换回 HEX 会有微小偏差?Why does HSL round-trip slightly off?

因为 HSL 的数值是四舍五入后的百分比和角度,再换回 0–255 的整数通道时,尾数被截掉了。偏差通常不超过 1,肉眼看不出来。需要精确往返时用 RGB 或 HEX 作为中间格式。 HSL values here are rounded percentages and whole degrees; converting back to integer 0–255 channels truncates the remainder. The error is usually under 1 and invisible. For exact round-trips, keep RGB or HEX as the intermediate.

「色阶」是按什么规则生成的?How are the tints and shades generated?

浅色是把当前色与白色按 10%–90% 的比例线性混合,深色是与黑色混合。这是设计系统里最常见的做法,比单纯改 HSL 亮度更稳定——后者在接近 0% 或 100% 时会失去色相。 Tints linearly mix the colour with white at 10–90%; shades mix with black. That's what design systems usually do, and it's more stable than nudging HSL lightness, which loses hue as it approaches 0% or 100%.