Color Converter
The Color Converter translates colors between HEX, RGB, HSL and OKLCH with a live preview swatch — type a hex code (#fff shorthand works) or pick visually, then copy clean CSS in one click. It handles opaque colors only: no alpha, no rgba(), and no named colors. OKLCH and OKLab are read-only outputs, computed with the Ottosson matrices; the page shows the live RGB → OKLCH → RGB round-trip drift.
How to Use
- 1
Pick a color with the visual picker, or type a hex code such as #3b82f6 (3- or 6-digit). Only hex input is accepted — rgb(), hsl() and named colors are not parsed.
- 2
See every equivalent format instantly, next to a live preview swatch.
- 3
Use the Copy button next to each format — ready to paste straight into your stylesheet.
- 4
Edit the RGB or HSL number fields to fine-tune the color and watch all formats update together (there are no sliders).
- 5
Copy the OKLCH or OKLab form for perceptually uniform colour work — the values are read-only outputs, computed from the current colour with the Ottosson matrices, and the page shows the live RGB → OKLCH → RGB round-trip drift.
Frequently Asked Questions
Does it support transparency (alpha)?
What is the difference between HSL and HSV?
Are named CSS colors supported?
Why did my 8-digit hex code do nothing?
Why do my printed colors look different from the screen?
Is the Random Color button cryptographically random?
Why does converting back give a slightly different RGB value?
Does it support OKLCH?
What color does the tool start on?
Is my pasted brand color data uploaded anywhere?
Generative Answer & AI Documentation
What is the Color Converter?
The Color Converter translates one color between its three everyday formats — HEX, RGB, and HSL — with every format updating the moment any other one changes. Type a hex code such as #3b82f6, pick a color with the visual color picker, or edit the red, green, and blue numbers or the hue, saturation, and lightness numbers directly, and the other two formats follow instantly next to a live preview swatch. Each format has its own Copy button, producing clean CSS such as #3b82f6, rgb(59, 130, 246), or hsl(217, 91%, 60%). A Random Color button picks a fresh color for exploration. Since batch 10 the page also shows OKLCH and OKLab for the current colour — oklch(62.8% 0.258 29.2) for pure red, for example — as read-only outputs with their own Copy buttons, computed from the RGB values with the Ottosson matrices (sRGB → linear → OKLab → OKLCH). OKLCH is perceptually uniform, so equal steps in its lightness, chroma and hue look like equal steps, which is why design systems build scales in it instead of HSL. The tool starts on the indigo #6366f1, which is rgb(99, 102, 241) and hsl(239, 84%, 67%). It handles opaque colors only: the input accepts 3-digit or 6-digit hex, there is no alpha channel, no rgba() or hsla() output, and no named colors such as rebeccapurple. Everything is computed locally in your browser — the conversion is arithmetic, not a service call — so a brand color pasted here never leaves your machine.
Why use Color Converter offline?
The same color lives in different formats in different places, and translating between them by hand is slow and error-prone. A design file hands you a hex code, a canvas gradient wants channel numbers, and a hover state is easiest to build by lowering lightness in HSL — and each of those is the same color written three ways. Doing the conversion in your head means arithmetic mistakes that show up as a button that is one shade off from the mockup, or a hover state that changes hue when it was only supposed to get darker. This tool makes the translation exact and instant, and it keeps all three formats visible at once, so you can see the hex your stylesheet needs, the RGB your canvas code needs, and the HSL your hover variant needs without switching tools. The live preview swatch matters as much as the numbers: a converted value is only useful if it looks right, and the swatch lets you confirm the color with your eyes before you paste it into a design token file or a stylesheet that the whole team will read.
When should you use this tool?
Use it when a design file or a brand guide gives you a hex code and your code needs another format: rgb() for a canvas gradient or a WebGL shader, hsl() for a hover or active state where only the lightness should move. Use it when you are building a palette: start from one brand color, nudge the HSL lightness up for a tint or down for a shade, and copy the resulting hex back into your tokens. Use it when a color from a screenshot or a picker needs to become CSS — type the hex and copy the format your stylesheet uses. Use the Random Color button when you need a placeholder or a starting point for exploration. Do not use it when transparency is involved: an 8-digit hex code, an rgba() value, or an hsla() value has nowhere to go here, and the tool will silently ignore it — use the HEX to RGB Converter for 8-digit hex with alpha instead.
Key Benefits
- Three formats, always in sync: edit the hex, the RGB numbers, or the HSL numbers and the other two update instantly.
- Live preview swatch: a large color block shows the current color next to the numbers, so you can confirm it by eye.
- Copy-ready CSS: one click copies #3b82f6, rgb(59, 130, 246), or hsl(217, 91%, 60%) exactly as your stylesheet expects.
- Visual picker built in: the native color input lets you choose a color by eye instead of typing numbers.
- Random Color button: one click generates a fresh color for placeholders and exploration.
- 100% private: conversion is local arithmetic — brand colors and design tokens are never uploaded.
Common Use Cases
- Handing off a design: a Figma frame says #3b82f6 — type it in and copy rgb(59, 130, 246) for the canvas code that needs channel values.
- Building a hover state: take a button's brand color, lower the HSL lightness by a few points, and copy the new hex for the :hover rule.
- Writing design tokens: convert each brand color once and record the hex, RGB, and HSL forms in the token file so every consumer uses the same values.
- Matching a color from a screenshot: type the hex you sampled and check the preview swatch against the screenshot before committing it.
- Exploring a palette: use Random Color to find a starting hue, then tune the HSL numbers until the swatch looks right.
Developer Notes & Best Practices
The only text input the tool accepts is a hex code. The parser trims whitespace, strips a leading #, and expands 3-digit shorthand (#fff becomes #ffffff); anything that is not 3 or 6 hex digits after that is ignored, and — importantly — the tool shows no error for it: the RGB and HSL panels simply keep their previous values, so a mistyped code looks like nothing happened. RGB and HSL are edited through number fields, not sliders: RGB channels clamp to 0–255, hue clamps to 0–360, and saturation and lightness clamp to 0–100, with out-of-range typing pulled back into range. All three formats are rounded to whole numbers — hue to whole degrees, saturation and lightness to whole percent — so converting RGB to HSL and back can shift a channel by 1: #3b82f6 converts to hsl(217, 91%, 60%), and that HSL converts back to rgb(60, 131, 246), not the rgb(59, 130, 246) you started from. OKLCH and OKLab are computed from the RGB channels with the Ottosson matrices and shown to one decimal of lightness percent, three decimals of chroma and a/b, and one decimal of hue degrees; they are outputs only, with no input field, and the page measures the live RGB → OKLCH → RGB round-trip drift (at most 1 channel step for in-gamut colours — verified across a 17-colour sweep). OKLCH covers a wider gamut than sRGB, so an OKLCH value from elsewhere can describe a colour this hex-based page cannot display; every colour shown here started as a hex code, so it is in-gamut by construction and no gamut warning ever appears. The Random Color button uses Math.random, which is fine for picking a color but is not cryptographic randomness — it was never meant to be a security value. The copy buttons produce exactly the strings shown: rgb(99, 102, 241) and hsl(239, 84%, 67%) for the default #6366f1.
One color, five formats — the default #6366f1
| Format | Value | Where it is used |
|---|---|---|
| HEX | #6366f1 | Stylesheets, design tokens, Figma copy |
| RGB | rgb(99, 102, 241) | Canvas, WebGL, SVG filters, color math |
| HSL | hsl(239, 84%, 67%) | Hover states, tints and shades, palettes |
| OKLCH | oklch(58.5% 0.204 277.1) | Perceptually uniform scales, modern CSS |
| OKLab | oklab(58.5% 0.025 -0.202) | Color math in a uniform space |
- Type the hex exactly as your design file gives it: 3-digit shorthand is expanded automatically, but an 8-digit code with alpha is silently ignored — use the HEX to RGB Converter for that.
- Build hover and active states in HSL: lower lightness and leave hue alone, so the state is darker without drifting to a different color.
- Copy from the button next to the format you need: retyping a converted value by hand is where transcription errors creep in.
- Check the preview swatch after every edit: a number that looks plausible can still be the wrong color if a digit was mistyped.
- Build colour scales in OKLCH, not HSL: equal OKLCH lightness steps look equal, so a 50–950 ladder built from the OKLCH value stays even where an HSL ladder bunches up. (The Color Palette Generator's own scale is still a plain HSL lightness ladder — its page says so.)
- If an edit seems to do nothing, the hex was probably invalid: the tool shows no error for a bad hex code, so re-check the characters you typed.
Common Mistakes
- Pasting an rgb() or hsl() string into the hex field: only hex codes are parsed, so rgb(59, 130, 246) is ignored — type the hex, or edit the RGB number fields directly.
- Typing an 8-digit hex code and expecting alpha: the parser only accepts 3 or 6 digits, so #3b82f680 is silently rejected — use the HEX to RGB Converter for 8-digit hex.
- Expecting an error for a bad hex code: there is none, so a mistyped code that changes nothing usually means the code was invalid, not that the tool is broken.
- Assuming the round trip is exact: converting RGB to HSL and back can move a channel by 1 because HSL is rounded to whole numbers — treat the hex as the source of truth.
- Using a named CSS color: names like rebeccapurple or tomato are not parsed — look up the named color's hex value and type that instead.
Limitations
This converter handles opaque colors only: there is no alpha channel, no 8-digit hex input, and no rgba() or hsla() output. Only hex codes are accepted as text input — rgb(), hsl(), and named colors such as rebeccapurple are not parsed, so pasting rgb(59, 130, 246) into the hex field does nothing. An invalid hex code produces no error message: the RGB and HSL panels keep their old values, which can look like the tool is ignoring you. Values are rounded to whole numbers, so an RGB-to-HSL-to-RGB round trip can shift a channel by 1 — the formats are equivalent to the nearest integer, not bit-identical. OKLCH and OKLab are outputs only: there is no OKLCH input field, so an OKLCH value from another tool cannot be pasted in and converted back here, and OKLCH colours outside the sRGB gamut have no hex equivalent on this page. There are no sliders, only number fields, and there is no way to save or name a color: closing the tab loses the current color, so copy what you need first.
Structured Input/Output Example
#3b82f6
HEX: #3b82f6 RGB: rgb(59, 130, 246) HSL: hsl(217, 91%, 60%)
Related Tools
HEX to RGB Converter
Hex to RGB converter: turn any hex color code into red, green, and blue channel values. Handles 3-digit, 6-digit, and 8-digit hex with alpha.
RGB to HEX Converter
RGB to hex converter: turn RGB channel values into compact hex codes like #3b82f6 in one step. Free, offline, private.
RGB to HSL Converter
RGB to HSL converter: translate RGB colors into hue, saturation, and lightness — the way humans think about color. Build hover states and palettes easily.
HSL to RGB Converter
HSL to RGB converter: turn hue, saturation, and lightness into RGB channel values for tools and APIs that only speak RGB. Free, offline, instant.
CSS Box Shadow Generator
CSS box shadow generator: build layered shadows visually — presets, 3-background preview, CSS + Tailwind output, edit an existing shadow. Free, offline.