PlayTools

颜色互转:设计令牌与动效插值

在 HEX、RGB、HSL 和 HSB 之间即时转换颜色,含可视化颜色选择器。

Runs in your browser — nothing you enter is uploaded

Click to pick

HEX#6366f1
RGBrgb(99, 102, 241)
HSLhsl(239, 84%, 67%)

颜色互转:设计令牌与动效插值

在 HEX、RGB、HSL 间互转有助于统一设计系统;动画常用 HSL 做更顺滑的色相插值。

屏幕色域与印刷 CMYK 不同,印刷校色需专业流程。

HEX, RGB and HSL describe the same colour

All three formats specify a colour in the sRGB colour space used by browsers. HEX is RGB written in base 16: #6366F1 means red 0x63 = 99, green 0x66 = 102 and blue 0xF1 = 241, so it is identical to rgb(99, 102, 241). HSL re-expresses the same colour as hue (an angle around the colour wheel, 0–360°), saturation and lightness (0–100%) — here hsl(239, 84%, 67%).

The converter accepts six-digit hex codes and the three-digit CSS shorthand, in which each digit is doubled: #FFF is #FFFFFF and #3A7 is #33AA77. Upper and lower case are equivalent.

Why HSL values do not always round-trip

HSL is shown in whole degrees and percentages, which is coarser than RGB. Converting #6366F1 to hsl(239, 84%, 67%) and back gives #6467F2 — one step brighter in each channel. The difference is invisible, but if you are matching a brand colour exactly, keep the HEX value as the source of truth and use HSL only for adjustments.

Using HSL to build a palette

  • Lighter and darker shades: keep hue and saturation, change lightness — hsl(239, 84%, 90%) for a background tint, hsl(239, 84%, 40%) for hover states.
  • Muted versions: lower the saturation while keeping hue and lightness.
  • Complementary colour: add 180° to the hue. Triadic colours sit 120° apart, analogous colours 30° either side.
  • Equal HSL lightness does not mean equal perceived brightness: yellow at 50% looks much lighter than blue at 50%. Check contrast rather than trusting the L value.

Checking text contrast

The Web Content Accessibility Guidelines (WCAG 2) require a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (about 24 px, or 19 px bold). Indigo #6366F1 on white measures 4.47:1 — just short for body text, though fine for large headings and buttons. A slightly darker #4F46E5 reaches 6.29:1. For neutral greys, #767676 is the lightest that passes 4.5:1 on white.

Screen and print

HEX, RGB and HSL describe light from a screen. Printing uses CMYK inks with a smaller range of reproducible colours, so very saturated screen colours — bright blues and greens especially — print duller. Ask your printer for their colour profile, or specify a Pantone reference, when an exact printed match matters.

Modern CSS colour syntax

Current CSS accepts space-separated values with an optional alpha after a slash — rgb(99 102 241 / 50%) and hsl(239 84% 67% / 0.5) — alongside the comma forms this tool outputs. Eight-digit hex adds alpha as the last two digits (#6366F180 is about 50% opacity); this converter works with opaque colours, so drop those two digits before pasting. Newer spaces such as oklch() describe colours more evenly for the eye and can reach wider-gamut displays, but HEX and RGB remain the common currency of design tools.

These free tools pair well with this page — open them in a new tab to finish your workflow.

常见问题

HEX、RGB和HSL有什么区别?

HEX是6位十六进制表示法(如#ff6600),常用于CSS和设计工具。RGB通过0–255的整数分别指定红、绿、蓝通道。HSL通过色调(0–360°)、饱和度(0–100%)和亮度(0–100%)描述颜色,在调色时对人类更直观。

如何将HEX转换为RGB?

将HEX值分成三对:第一对是红色,第二对是绿色,第三对是蓝色。将每对从十六进制转换为十进制。例如,#1a2b3c → R=0x1a=26, G=0x2b=43, B=0x3c=60,即RGB(26, 43, 60)。

不透明度/透明度(alpha)是什么意思?

Alpha是第四个通道(0–1或0–100%),控制透明度。Alpha为0表示完全透明,1(或100%)表示完全不透明。在CSS中表示为rgba()或hsla(),或8位HEX如#rrggbbaa。

为什么颜色在屏幕和打印时看起来不同?

屏幕使用加色法RGB光——红+绿+蓝=白。打印机使用减色法CMYK油墨——青+品红+黄+黑=黑。相同的HEX值在不同设备上因颜色配置文件和色域不同而显示不同。

什么是色域?

色域是设备能够再现的颜色范围。sRGB是最常见的Web标准。宽色域显示器(DCI-P3、Rec. 2020)能显示更鲜艳的颜色。超出显示器色域的颜色会被裁剪或色调映射。

如何找到颜色的互补色?

互补色在色轮上与原色直接对立。在HSL中,只需在色调值上加(或减)180°。例如,色调60°(黄色)的互补色为色调240°(蓝色)。

HEX颜色代码区分大小写吗?

不区分。#FF6600和#ff6600完全相同。CSS将HEX颜色代码视为不区分大小写的。但许多开发者和风格指南为保持一致性而倾向于使用小写。