🎨 CSS

CSS Color Picker & Converter

Pick a color visually or type HEX, RGB, HSL, or OKLCH strings. Inspect real-time conversions with alpha transparency and Tailwind CSS export.

Curated Color Presets
#3b82f6

CSS Color Picker and Multi-Format Conversion Guide

Quick Answer: The CSS Color Picker & Converter provides an interactive visual color picker that instantly converts colors between HEX, RGB, HSL, HSV, OKLCH, and CMYK formats. Features include live alpha transparency control, clipboard copying, and 100% client-side execution.

Color representation in CSS has expanded significantly from early three-digit hex codes to modern perceptual color spaces. This tool lets you select colors visually or enter raw strings across HEX, RGB, HSL, OKLCH, HSV, and CMYK formats. The parser automatically detects the input format without forcing manual dropdown selection. It maintains exact consistency across all values, including alpha transparency channels.

Color Format Feature and Compatibility Matrix

Color Model CSS Syntax Example Perceptual Uniformity Gamut Support Primary Use Case
HEX (#rrggbbaa) #3b82f6cc Non-uniform (sRGB) Standard sRGB (24-bit) Compact storage, design handoff, HTML attributes
RGB / RGBA rgb(59 130 246 / 0.8) Non-uniform (sRGB) Standard sRGB (0-255 channels) Direct hardware rasterization, canvas manipulation
HSL / HSLA hsl(217 91% 60% / 0.8) Non-uniform cylindrical Standard sRGB Human intuitive tweaking (hue, saturation, lightness)
OKLCH oklch(0.62 0.19 255 / 0.8) Perceptually Uniform Wide Gamut (Display P3, Rec. 2020) Modern design systems, accessible palette generation
HSV / HSB hsv(217, 76%, 96%) Non-uniform cylindrical Application UI model Graphic software color pickers, digital painting tools
CMYK cmyk(76%, 47%, 0%, 4%) Subtractive physical Print ink gamut Physical print collateral, commercial offset printing

The Physics and Biology of Digital Color: From Photons to sRGB

To understand digital color conversion, engineers must inspect how physical display monitors render imagery. Computer screens utilize additive color mixing: pixels consist of microscopic subpixel clusters of Red, Green, and Blue light-emitting elements. By varying electrical voltage across these subpixels, screens stimulate the three types of cone photoreceptors in the human retina (L, M, and S cones), producing the sensation of full-spectrum color.

In 1996, HP and Microsoft standardized the sRGB color space to establish a shared color gamut across cathode-ray tube (CRT) monitors, digital cameras, and the emerging World Wide Web. Under 8-bit sRGB architecture, each primary channel is discretized into an integer value between 0 (complete darkness) and 255 (maximum luminous intensity). Combining 256 red levels, 256 green levels, and 256 blue levels yields 256 * 256 * 256 = 16,777,216 distinct color possibilities.

Deconstructing Digital Color Formats: HEX, RGB, HSL, and HSV

Different color notations represent alternative mathematical coordinate models mapped across the underlying sRGB color cube:

The Revolution of CSS Color Module Level 4

The CSS Color Module Level 4 specification modernized how color functions are declared in web stylesheets:

Perceptually Uniform Color Spaces: The Power of OKLCH

While HSL is intuitive, it suffers from a fundamental mathematical flaw: it is not perceptually uniform. Human eyes are biologically evolved to be far more sensitive to green and yellow light than to blue light. In HSL, pure blue (hsl(240, 100%, 50%)) and pure yellow (hsl(60, 100%, 50%)) both share a 50% lightness value. Yet to human vision, yellow appears brilliantly luminous while blue looks dark and somber.

This perceptual inconsistency creates severe problems in UI design: changing a button hue from blue to yellow while holding lightness constant produces an unreadable white-on-yellow contrast failure. Enter OKLCH (Oklab Lightness, Chroma, Hue), developed by Björn Ottosson in 2020 and standardized in modern CSS engines:

Hexadecimal Color Mathematics and Bitwise Alpha Encoding

Eight-digit hex notation (#rrggbbaa) packs a 32-bit color integer into an 8-character string. Converting an alpha opacity float (e.g., 0.85) into a two-digit hexadecimal channel requires multiplying the decimal fraction by 255, rounding to the nearest integer, and formatting in base-16:

Hex Alpha = Math.round(0.85 * 255).toString(16).padStart(2, "0") = "d9"

Conversely, extracting the alpha percentage from a hex string parses the final two characters as a base-16 integer and divides by 255: parseInt("d9", 16) / 255 = 217 / 255 = 0.851. This reversible mathematical mapping guarantees instant parity across hex, decimal, and percentage transparency displays.

Mathematical Conversion Algorithms: RGB to HSL

The conversion from 8-bit RGB coordinates (r, g, b in [0, 255]) to HSL parameters (h, s, l) operates as follows:

  1. Normalize channels: R = r / 255, G = g / 255, B = b / 255.
  2. Identify extrema: max = Math.max(R, G, B) and min = Math.min(R, G, B).
  3. Calculate delta: d = max - min.
  4. Compute Lightness: L = (max + min) / 2.
  5. Compute Saturation: If d === 0, saturation is 0 (achromatic gray). Otherwise, S = L > 0.5 ? d / (2 - max - min) : d / (max + min).
  6. Compute Hue: If max === R, H = ((G - B) / d + (G < B ? 6 : 0)) * 60. If max === G, H = ((B - R) / d + 2) * 60. If max === B, H = ((R - G) / d + 4) * 60.

Because whole-integer degrees and percentages round off trailing decimals for clean presentation, repeated back-and-forth round trips between RGB and HSL can occasionally shift a channel value by a single integer unit. This precision variance is standard across all digital graphics software.

Color Systems in Production: Theming and Design Tokens

In modern web applications, colors should rarely be hardcoded as raw hex strings in component files. Instead, declare foundational palette tokens as CSS custom properties:

:root {
  --primary-hue: 217deg;
  --primary-saturation: 91%;
  --primary-lightness: 60%;
  --color-primary: hsl(var(--primary-hue) var(--primary-saturation) var(--primary-lightness));
}

Structuring color variables into decoupled hue, saturation, and lightness tokens enables straightforward dark-mode theming, high-contrast accessibility modes, and user-selected brand accent customization simply by overriding root variables.

Tailwind CSS Integration Strategies

Tailwind CSS supports color values through two versatile approaches:

Frequently Asked Questions

How does the tool know if I typed hex, RGB, or HSL?

It tests your input against three regular expressions in order: hex first, then rgb()/rgba(), then hsl()/hsla(), and uses whichever pattern matches. There is no manual format selector because the parser detects the format automatically from the syntax you typed.

Can I type both legacy comma syntax and modern space/slash CSS syntax?

Yes. Both rgb()/rgba() and hsl()/hsla() patterns accept the classic comma-separated syntax and the CSS Color Module 4 space-separated syntax with a slash before alpha, along with an optional deg suffix on the hue value.

Does hex code syntax support transparency in CSS?

Yes. Hex supports 8-digit notation (#rrggbbaa) and 4-digit shorthand (#rgba), where trailing characters encode alpha. It is standard CSS supported in all modern browsers since 2017.

Why is there an alpha slider instead of using the color picker directly?

The native HTML color picker element only stores an opaque 6-digit hex value with no alpha transparency support. This tool tracks alpha independently on its own slider, feeding RGBA, HSLA, OKLCH, and the preview swatch.

Will typing in the input box get overwritten while I type?

No. The tool tracks whether an update comes from user typing versus picker interaction. It avoids rewriting the text field while you type so your raw keystrokes remain stable while other formats update.

Why can converting RGB to HSL and back introduce slight value drift?

HSL values round to whole-number degrees and percentages for readability. Rounding fractions can cause a 1-unit difference in RGB channels during round-trip conversions, which is standard across digital color calculations.

What is OKLCH and why is it superior to HSL for UI design systems?

OKLCH is a perceptually uniform color space where lightness (L) and chroma (C) remain consistent across all hues (H). Unlike HSL, where yellow appears much brighter than blue at identical lightness values, OKLCH guarantees uniform perceived brightness.

How does the alpha hex channel convert to decimal opacity?

Hex alpha maps from 00 (0 in decimal) to FF (255 in decimal). Decimal opacity equals the hexadecimal integer divided by 255, so 80 in hex equates to 128 divided by 255, or approximately 0.50 opacity.

How can I use converted color codes in Tailwind CSS?

You can use arbitrary values directly like bg-[#3b82f6] or text-[hsl(217,91%,60%)], or define theme colors in your tailwind.config.js file referencing CSS variables for dynamic light and dark theme switching.

Does modern CSS require commas inside rgb() and hsl() functions?

No. CSS Color Module Level 4 standardized space-separated syntax without commas, using a forward slash for alpha transparency, such as rgb(59 130 246 / 0.8) and hsl(217 91% 60% / 0.8).