Hex Color Converter

Converts colour values between HEX, RGB, and HSL formats in real time. Includes a native colour picker, a live colour preview panel, ready-to-copy CSS snippets, and common colour swatches. Useful for web developers, UI designers, and anyone translating colour formats for CSS, design tools, or print.

S. Siddiqui

Edited by

S. SiddiquiFounder & Editor-in-Chief
Sources:NISTSI BrochureBIPMUpdated Jul 2026
Click to pick any colour

rgb(59, 130, 246)

hsl(217, 91%, 60%)

CSS Snippets

color: #3B82F6;
background-color: rgb(59, 130, 246);
border-color: hsl(217, 91%, 60%);

Common colours

Quick Answer: The hex code #3B82F6 is rgb(59, 130, 246) and hsl(217, 91%, 60%). Enter any hex, RGB, or HSL value above and all three formats update instantly alongside a live colour preview.

What Is a Hex Colour Converter?

A hex colour converter translates colour values between the three formats used most commonly in digital design and web development: hexadecimal (HEX), red-green-blue (RGB), and hue-saturation-lightness (HSL). Each format describes exactly the same colour using a different mathematical model. HEX and RGB define colour by specifying the intensity of red, green, and blue light on a scale from 0 to 255. HSL instead describes colour using how humans perceive it: the hue (the colour wheel position), the saturation (colour intensity), and the lightness (how bright or dark the colour appears).

Web browsers, CSS specifications, design tools like Figma and Sketch, image editors, and print workflows all accept different colour notation. A designer hands off a brand colour as #FF6B35; the developer needs rgb(255, 107, 53) for a canvas API call; the brand guide specifies hsl(18, 100%, 60%) for programmatic tint generation. The converter moves fluently between all three without rounding errors.

Hexadecimal colour notation is rooted in the same binary-to-hex principle used in computing: each pair of hex digits represents one byte (0 to 255) for one colour channel. The MDN Web Docs CSS colour value reference documents every colour format supported by modern browsers. The W3C CSS Color Level 4 specification defines the exact mathematical relationships between HEX, RGB, HSL, and newer formats like oklch.

How to Use the Hex Colour Converter

  1. Click the colour swatch on the left to open your browser's native colour picker and choose any colour visually.
  2. Alternatively, type a hex code directly into the HEX field (with or without the # symbol).
  3. Or enter red, green, and blue values (0 to 255) into the three RGB fields.
  4. Or enter hue (0 to 360), saturation (0 to 100), and lightness (0 to 100) into the HSL fields.
  5. All other formats update in real time as you type in any field.
  6. The colour preview panel at the top shows the live result of your current values.
  7. Copy any format or CSS snippet using the copy icons next to each field.
  8. Click one of the common colour swatches at the bottom to load a preset colour instantly.

HEX vs RGB vs HSL: Key Differences

FormatNotationRangeBest ForExample (blue)
HEX#RRGGBB00 to FF per channelCSS stylesheets, design handoff, brand guides#3B82F6
RGBrgb(R, G, B)0 to 255 per channelCanvas API, image processing, programmatic mixingrgb(59, 130, 246)
HSLhsl(H, S%, L%)0-360, 0-100%, 0-100%Generating tints, shades, and colour scaleshsl(217, 91%, 60%)

When to Use the Hex Colour Converter

The Web Developer Implementing a Design System

A developer receives a Figma file where brand colours are specified as hex codes: primary #1E40AF, hover #1D4ED8, active #1E3A8A. They need to create CSS custom properties that also include HSL values for programmatic tint generation. They enter #1E40AF and read HSL 224, 72%, 40%. They can now define a CSS custom property for the hue value (224) and generate the full tonal palette by passing it into hsl() with variable lightness values without separately calculating each shade.

The UI Designer Checking Colour Contrast

A designer is reviewing WCAG accessibility compliance for a web application. The background is #F3F4F6 (a light grey) and the text is #374151 (dark grey). They convert both to RGB to feed into a contrast ratio calculation: the background is rgb(243, 244, 246) and the text is rgb(55, 65, 81). The relative luminance formula requires RGB values, making the conversion a necessary step before checking the 4.5:1 minimum ratio for normal text.

The Game Developer Specifying Particle Colours

A Unity game developer uses a particle system that accepts HSL values for dynamic colour cycling. The art director specifies a flame effect that should transition from #FF4500 (orange-red) through #FF8C00 (dark orange) to #FFD700 (gold). The developer converts all three to HSL: hsl(16, 100%, 50%), hsl(33, 100%, 50%), and hsl(51, 100%, 50%). The hue values increase linearly from 16 to 51, confirming the designer intended a smooth hue rotation that can be animated with a single lerp on the H channel.

The Print Designer Converting to Screen Colours

A graphic designer receives a brand colour specified for print as Pantone 286 C. The nearest digital equivalent is approximately rgb(0, 56, 168). They enter those RGB values and get hex #0038A8 for the web team and HSL 221, 100%, 33% for the UI team who are building a dark-mode variant at HSL 221, 100%, 50%. The HSL representation immediately shows that the dark-mode version simply needs the lightness raised by 17 percentage points.

Common Mistakes When Converting Colour Formats

Forgetting that HSL lightness 50% is not a mid-grey confuses many designers who are new to the format. In HSL, lightness 50% at full saturation produces the purest version of the hue. Mid-grey has saturation 0% and lightness 50%. To desaturate a colour without changing its perceived brightness, reduce the saturation rather than the lightness.

Rounding RGB values before converting to hex produces off-by-one errors that compound across a colour palette. If you compute RGB values as floating-point numbers from a formula and round each to the nearest integer before hex conversion, the output hex code may differ slightly from the input you started with. Always convert without intermediate rounding where possible.

Assuming web-safe colours still matter is outdated thinking. Web-safe colours were 216 specific hex codes that displayed consistently on 8-bit monitors in the 1990s. Modern displays support 16.7 million colours (24-bit). There is no need to restrict your palette to multiples of 33 in hex.

Confusing HSL and HSV (also called HSB) is easy because both formats use a hue-saturation model. HSL and HSV define saturation and the third channel differently. In HSL, a fully saturated colour at lightness 100% is white. In HSV, a fully saturated colour at value 100% is the pure hue. Adobe tools typically use HSB; CSS uses HSL. Converting between them requires a formula, not a simple rename.

The Mathematics Behind Colour Format Conversion

Every colour format conversion follows a precise mathematical path. No information is lost in the round trip from HEX to RGB to HSL and back, provided rounding is applied only at the final step. Understanding the formulas helps when you need to automate conversions in code or verify that a tool is producing correct results.

HEX to RGB

Split the six-digit hex code into three pairs. Convert each pair from hexadecimal to decimal. The first pair is red (R), the second is green (G), the third is blue (B). For #3B82F6: 3B = 59 (red), 82 = 130 (green), F6 = 246 (blue). Result: rgb(59, 130, 246).

RGB to HSL

Normalise R, G, B to the range 0 to 1 by dividing each by 255. Find the maximum and minimum of the three values. Lightness L = (max + min) / 2. Saturation S = (max - min) / (1 - |2L - 1|) when L is not 0 or 1. Hue H is calculated from which channel holds the maximum value, using a formula that places it on the 0 to 360 degree circle.

HSL to RGB

The reverse calculation uses the chroma (C = (1 - |2L - 1|) x S) and an intermediate value X to reconstruct R, G, B from the hue quadrant. The final RGB values are obtained by adding the lightness offset m = L - C/2 to each intermediate component.

Colour Contrast and Accessibility

Web Content Accessibility Guidelines (WCAG) 2.1 require a minimum contrast ratio of 4.5:1 for normal text and 3:1 for large text against their background. Contrast ratio is calculated from the relative luminance of two colours. Relative luminance is derived from the linearised RGB values (applying a gamma correction to each channel) using the formula L = 0.2126 R + 0.7152 G + 0.0722 B.

This means that converting a design's colour to RGB is always the necessary first step before checking WCAG compliance. The HSL lightness value alone is not sufficient, because two colours with the same HSL lightness can have different relative luminance values depending on their hue and saturation.

Common high-contrast pairings that pass WCAG AA: black text (#000000) on white background (#FFFFFF) achieves a 21:1 ratio. Dark blue (#1E40AF) on white achieves approximately 7.2:1. Light grey text (#9CA3AF) on white only achieves 2.5:1, which fails the 4.5:1 threshold for normal text.

Colour Spaces Beyond HEX, RGB, and HSL

HEX, RGB, and HSL are the three colour formats you encounter most often in web development, but they are all representations of the same sRGB (standard Red Green Blue) colour space. Understanding where sRGB fits in the broader landscape of colour science helps when you encounter colour problems that HEX and RGB alone cannot solve.

sRGB was standardised in 1996 for computer monitors and has been the default colour space for the web ever since. It covers a subset of human visual perception called a gamut. Modern displays, particularly wide-gamut monitors and OLED screens on mobile devices, can reproduce colours outside the sRGB gamut. CSS now supports wider gamut formats like Display P3 (used in Apple devices) and rec2020 (used in HDR video). Colours specified in these wider gamuts that fall outside sRGB are automatically mapped back to the nearest sRGB equivalent in browsers that do not support them.

oklch and oklab are newer CSS colour spaces that solve a fundamental problem with HSL: two colours with the same HSL lightness value do not necessarily look equally bright to the human eye. A saturated yellow at HSL 60, 100%, 50% appears much brighter than a saturated blue at HSL 240, 100%, 50%, even though they have identical lightness values. The oklab model was designed to make equal numerical steps in lightness correspond to equal perceived changes in brightness, making it more reliable for generating accessible colour scales.

Colour in Print vs Digital: Understanding the Gap

Digital colour (RGB) and print colour (CMYK) use fundamentally different models. RGB is additive: mixing full red, green, and blue light produces white. CMYK is subtractive: mixing full cyan, magenta, yellow, and black ink produces near-black. Converting between them is not a precise mathematical operation; it requires colour profiles that model the specific behaviour of inks on paper and the rendering intent (relative colorimetric, perceptual, saturation, or absolute colorimetric) chosen for the conversion.

When a brand designer specifies a colour that exists vividly on a printed brochure (a bright orange, a vivid teal), there is a real risk that the nearest RGB equivalent looks duller on screen. The CMYK gamut, while smaller than sRGB for some colours, can actually exceed sRGB for certain highly saturated greens and yellows that are achievable with ink but not with the RGB primaries of standard monitors. Professional print-to-screen colour workflows use ICC colour profiles and specialist software to manage these conversions; a simple hex converter is a starting point for approximation, not a substitute for colour-managed workflows in brand-critical contexts.

For most web and UI work, the HEX to RGB to HSL triangle covers everything needed. When print accuracy matters, consult a professional with calibrated hardware and colour management software.

Frequently Asked Questions

Last reviewed: July 26, 2026
Founder's Real-World Experience
S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief, YourToolsBase

How I resolved a brand colour discrepancy between a client's print materials and their new website using a hex converter

In February 2026 I was overseeing the launch of a new website for a professional services client in Birmingham. The brand had been established through printed materials over several years: brochures, business cards, and a banner stand all using a specific shade of teal. The graphic designer who handled print had always specified the colour as a Pantone reference and a CMYK breakdown. The web development agency needed a hex code.

The developer's best guess was #008B8B, a standard CSS named colour called "dark cyan." When I held a printed brochure next to the browser window on a calibrated monitor, the colours were visibly different. The printed teal leaned more towards blue-green; the web version read as greenish-grey.

I opened the hex colour converter and entered the developer's initial code. The HSL breakdown showed hsl(180, 100%, 27%). I compared this against the print CMYK values the designer had archived: C100 M0 Y35 K0. Converting CMYK to RGB and then to hex using the converter as a check: C100 M0 Y35 K0 maps approximately to rgb(0, 168, 110), which is hex #00A86E and HSL 154, 100%, 33%. The hues were 26 degrees apart on the colour wheel, explaining the visible mismatch.

After adjusting to #00A86E and checking the contrast ratio against white text, we had a web colour that matched the printed materials closely enough to satisfy the client and passed WCAG AA for body text. The converter gave us the HSL breakdown that let us reason about the hue difference systematically rather than guessing iteratively.

Hue discrepancy of 26 degrees identified between print CMYK and web hexCorrected to #00A86E matching brand teal within monitor calibration limitsWCAG AA contrast ratio confirmed before sign-off
Also used alongside: Number Base Converter

Frequently Asked Questions

What does each pair of digits in a hex colour code mean?
A hex colour code like #3B82F6 contains three pairs: 3B (red), 82 (green), and F6 (blue). Each pair is a hexadecimal number from 00 to FF, representing an intensity from 0 to 255 for that colour channel. 00 means none of that colour; FF means full intensity.
What is the difference between HEX and RGB colour formats?
They encode the same information differently. HEX expresses each channel as a two-digit hexadecimal number (00 to FF). RGB expresses each channel as a decimal number (0 to 255). The colour #FF0000 and rgb(255, 0, 0) are identical: both describe pure red at full intensity with no green or blue.
When should I use HSL instead of RGB or HEX?
Use HSL when you need to programmatically create colour variations: tints (lighter versions), shades (darker versions), or analogous colours. Adjusting the L value in HSL makes a colour lighter or darker in a predictable, perceptually consistent way. Doing the same in RGB requires changing all three channels simultaneously.
What does a hex colour code with only 3 digits mean?
A 3-digit hex code is shorthand for a 6-digit code where each digit is doubled. #F36 expands to #FF3366. This shorthand only works when both digits of each pair are identical. It is valid in CSS and saves a few characters in stylesheets, but is less common in design tools that always output 6-digit codes.
What is the HSL hue value for common colours?
The hue circle in HSL runs from 0 to 360 degrees. Red is 0 (and 360), yellow is 60, green is 120, cyan is 180, blue is 240, and magenta is 300. Values between these produce intermediate hues. White, black, and grey have no meaningful hue because their saturation is 0.
What is the hex code for transparent or no colour?
Standard 6-digit HEX codes do not include transparency. For transparent colours in CSS, use an 8-digit hex code where the last two digits represent opacity: #3B82F680 is the same blue at 50% opacity (80 in hex = 128 in decimal, approximately 50% of 255). Alternatively, use rgba() with a fourth value from 0 (fully transparent) to 1 (fully opaque).
Why does my screen colour look different from the printed colour?
Screens use RGB (additive colour mixing with light), while printing uses CMYK (subtractive colour mixing with ink). The same RGB values can appear very different when printed, especially for highly saturated blues and greens. Professional print workflows convert RGB to CMYK using ICC colour profiles before sending to press.
How do I find the hex code for a colour I see on screen?
Browser developer tools include a colour picker that can sample any pixel on the page. In Chrome, open DevTools, click any colour swatch in the Styles panel, and use the eyedropper tool to click anywhere on the screen. Design tools like Figma and Sketch also include eyedroppers. For system-wide colour sampling, tools like Colour Picker (macOS) or PowerToys Colour Picker (Windows) work across any application.
What is RGBA and how does it differ from RGB?
RGBA adds a fourth channel for alpha (opacity) to standard RGB. The alpha value ranges from 0 (fully transparent) to 1 (fully opaque) in CSS notation: rgba(59, 130, 246, 0.5) is the same blue at 50% opacity. Most browsers also accept the 8-digit hex format (#3B82F680) as an alternative notation.
What is the most common colour format to use in CSS?
HEX is the most widely used format in CSS for static colour values because it is compact and immediately recognisable in code review. HSL has gained popularity for design systems and component libraries because it makes colour manipulation (lighter, darker, more saturated) readable in code. RGB and RGBA are preferred when colour values are computed dynamically in JavaScript.

Rate This Tool

Was this tool helpful?

Be the first to rate this tool

About the Author

S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief

LinkedIn Profile

S. Siddiqui is the founder and editor-in-chief of YourToolsBase, overseeing all content, tool accuracy, and editorial standards.

View full profile

Authoritative Sources

Formulas and data in this tool are based on guidelines from the above sources.