Color 选择器

在不同表示(十六进制、rgb、hsl 和 CSS 名称)之间轻松转换颜色

color picker:
#13423FF
name:
hex:
rgb:
hsl:
hwb:
lch:
cmyk:

What is Color Conversion?

Color conversion is the process of transforming a color from one representation format to another. In web design, UI development, digital image processing, and many other fields, different tools and frameworks require different color formats. For instance, CSS stylesheets support hexadecimal color codes (e.g., #FF5733), RGB/RGBA notation (e.g., rgb(255,87,51)), and HSL notation (e.g., hsl(12,100%,60%)), while design software may use more specialized color spaces like CMYK or LCH. A color conversion tool bridges these formats for quick and seamless transformation.

Common Color Formats Explained

1. Hexadecimal Color Codes (HEX)

Hexadecimal color codes are the most commonly used color representation in web development. They begin with #, followed by six (or three shorthand) hexadecimal digits, each pair representing the brightness of Red (R), Green (G), and Blue (B), ranging from 00 to FF (0~255 in decimal).

  • Example: #FF5733 means Red 255, Green 87, Blue 51.
  • Shorthand: #F53 is equivalent to #FF5533 — browsers automatically expand it to six digits.
  • Typical uses: CSS color properties, HTML tag attributes, color picker values in design tools.

2. RGB / RGBA Color Model

RGB (Red, Green, Blue) is the most fundamental color model in computer graphics, generating colors by mixing light from the three primary colors. RGBA adds an Alpha (transparency) channel to RGB, with values ranging from 0 to 1.

  • Example: rgb(255, 128, 0) or rgba(255, 128, 0, 0.5)
  • Typical uses: CSS color values, Canvas API, WebGL shaders.

3. HSL Color Model

HSL (Hue, Saturation, Lightness) is a more intuitive way to describe colors compared to RGB. While RGB requires mental arithmetic to guess the resulting color, HSL allows developers to directly adjust the "vividness" and "brightness" of a color.

  • H (Hue): 0°–360°, corresponding to the angle on the color wheel. 0° = red, 120° = green, 240° = blue.
  • S (Saturation): 0%–100%. 0% is gray, 100% is the most vivid.
  • L (Lightness): 0%–100%. 0% is pure black, 100% is pure white, 50% is normal.
  • Example: hsl(12, 100%, 60%) — highly saturated, medium-light reddish hue.

4. HWB Color Model

HWB (Hue, Whiteness, Blackness) is a color notation introduced in the CSS Color Level 4 specification. It defines a color by specifying the hue and the amount of white and black mixed in, making it more intuitive than HSL in many scenarios.

  • Example: hwb(12 10% 20%) — hue 12°, mixed with 10% white and 20% black.

5. LCH Color Space

LCH (Lightness, Chroma, Hue) is a next-generation color representation based on the CIE Lab color space. Its biggest advantage is perceptual uniformity — equal numerical changes correspond to equal perceptual changes, solving the uneven color gradient problem in RGB and HSL.

  • L (Lightness): 0%–100%, describing how light or dark the color is.
  • C (Chroma): Describes the saturation or vividness; 0 is gray.
  • H (Hue): 0°–360°, same meaning as hue in HSL.

6. CMYK Color Model

CMYK (Cyan, Magenta, Yellow, Key/Black) is the standard color model for the printing industry. Unlike RGB's additive method (light adds up to become brighter), CMYK uses a subtractive method (ink overlays absorb light), making it the essential color model for print and publishing.

  • Example: device-cmyk(0% 60% 80% 0%) — 0% cyan, 60% magenta, 80% yellow, 0% black.

7. CSS Named Colors

The CSS specification defines 148 standard named colors, such as red, blue, darkgreen, and tomato. These color names work directly in browsers with great readability, ideal for rapid prototyping.

RGB ↔ HEX Conversion Principle

The conversion between RGB and HEX is straightforward mathematics:

  • RGB → HEX: Convert each decimal R, G, B value to a two-digit hexadecimal number and concatenate. For example, RGB(255, 87, 51) → FF + 57 + 33 → #FF5733.
  • HEX → RGB: Split the six hex digits into three pairs and convert each pair to decimal. For example, #1A2B3C → 1A=26, 2B=43, 3C=60 → RGB(26, 43, 60).

RGB ↔ HSL Conversion Principle

RGB → HSL conversion involves normalizing RGB values to the [0,1] range, finding the min and max to calculate Lightness, computing Saturation from the range, and determining Hue from the relative channel differences. HSL → RGB is a piecewise function based on which 60° sector of the color wheel the hue falls into.

Use Cases for Color Conversion Tools

ScenarioDescription
Frontend DevelopmentCSS supports multiple color formats; developers frequently switch between design specs (HEX) and code implementation (RGB/HSL).
UI/UX DesignDesigners use HEX in Figma and Sketch; frontend developers may need RGB or HSL for transparency control or color variant calculation.
Print DesignScreens display RGB while printing uses CMYK — accurate color conversion is key to consistent print results.
Canvas / WebGLCanvas API and WebGL shaders often require normalized [0,1] floating-point RGB values.
Data VisualizationWhen generating gradient color scales or heatmaps, operating in HSL space produces more perceptually uniform transitions than RGB.
Dynamic Theme GenerationQuickly derive a complete theme color system from a primary color by adjusting lightness/saturation in HSL.

Why Use an Online Color Conversion Tool?

In daily development, developers often need to quickly check how a color looks in different formats — for example, taking a hexadecimal value from a design mockup and expressing it as RGB for CSS variables, or looking up the nearest CSS named color for an RGB value. Manually calculating each time or juggling multiple browser tabs is inefficient. Our online color converter provides an all-in-one solution:

  • Real-time bidirectional conversion: Type or edit a color value in any format input field, and all other formats update instantly. Supports HEX, RGB, HSL, HWB, CSS names, and more as input.
  • Built-in color picker: A visual color selector for intuitive color choosing.
  • One-click copy: Each format has a copy button alongside — one click copies to the clipboard.
  • 100% Local: All color calculations happen in your browser — no data is ever uploaded to any server. No installation required. Safe and reliable.

Whether you're a frontend engineer, UI designer, or full-stack developer, this is an indispensable tool in your daily workflow.