Convert colour codes instantly between HEX, RGB, and HSL. Enter a HEX code, an RGB value, or an HSL value and this tool updates all three formats in real time along with a live colour preview. Copy any format with one click.
Showing colour:
#3b82f6
Computer screens mix red, green, and blue light to produce every visible colour. The three common notation systems (HEX, RGB, and HSL) are simply different ways to express the same underlying RGB values.
HEX encodes R, G, and B as two-character hexadecimal numbers (0-9, a-f) concatenated into a six-character string prefixed with #. The range 00 to ff in hex corresponds to 0 to 255 in decimal. A shorthand three-character form exists where each digit is doubled: #39f is the same as #3399ff.
RGB expresses each channel as a decimal integer from 0 (none) to 255 (full intensity). The CSS function is rgb(r, g, b). The total number of colours representable is 256 x 256 x 256 = 16,777,216.
HSL was designed to be more intuitive for humans. Hue is the pure colour position on a 360-degree wheel (0 and 360 are red, 120 is green, 240 is blue). Saturation is how vivid the colour is as a percentage (0% is greyscale, 100% is fully saturated). Lightness describes how bright it is (0% is black, 100% is white, 50% is the full colour). Designers often prefer HSL because adjusting a single property produces predictable results.
| Conversion | Method |
|---|---|
| HEX to RGB | Parse each 2-char hex pair with parseInt(pair, 16). Short codes: double each digit first. |
| RGB to HEX | Convert each 0-255 integer to a 2-digit hex string: channel.toString(16).padStart(2,'0'). |
| RGB to HSL | Normalise to 0-1. L = (max+min)/2. S = (max-min)/(1-|2L-1|) when max != min. H from dominant channel. |
| HSL to RGB | C = (1-|2L-1|) x S. X = C x (1-|(H/60) mod 2 - 1|). Rotate (C,X,0) by H sector, add m = L - C/2. |
Starting with #3b82f6:
HEX is the most widely used format in web development and design tools. Use it in CSS for static colour values. RGB is useful when you need to manipulate individual colour channels in code or apply opacity using rgba(r, g, b, a). HSL is ideal when you want to create colour palettes or modify a colour predictably, for example darkening a brand colour by reducing lightness by 10%.
This converter also shows perceived brightness using the W3C relative luminance formula: Y = 0.2126R + 0.7152G + 0.0722B (where R, G, B are linearised). A relative luminance above about 0.179 is treated as a light colour and is best paired with dark text; at or below 0.179 it is treated as dark and is best paired with white or light text. This 0.179 figure is the WCAG crossover point, the luminance at which black and white text give equal contrast, so it predicts the more legible choice more reliably than a simple midpoint would. This is useful for ensuring sufficient colour contrast for accessibility (WCAG 2.1). For the default #3b82f6 the luminance is about 0.235, so the tool treats it as a light colour and suggests black text.
Sources and method: W3C CSS Color Level 4 specification (w3.org/TR/css-color-4). W3C WCAG 2.1 relative luminance definition (w3.org/TR/WCAG21/#dfn-relative-luminance). Conversions are performed entirely in the browser using standard floating-point arithmetic.
This tool converts colour codes exactly using the standard formulas. Results are correct to the nearest integer for each channel. Minor rounding differences may appear compared to some design software due to different intermediate precision choices.
If you've found a bug, or would like to contact us, or learn more about James Graham and Calculate.co.nz.
Calculate.co.nz is partnered with Interest.co.nz for New Zealand's highest quality calculators and financial analysis.
Calculate.co.nz is the sister site of CalculatorHub.com, the world's largest calculator website by tool count.
All calculators and tools are provided for educational and indicative purposes only and do not constitute financial advice.
Calculate.co.nz is proudly part of the Realtor.co.nz group, New Zealand's leading property transaction literacy platform, helping Kiwis understand the home buying and selling process from start to finish. Whether you're a first home buyer navigating your first property purchase, an investor evaluating your next acquisition, or a homeowner planning to sell, Realtor.co.nz provides clear, independent, and trustworthy guidance on every step of the New Zealand property transaction journey.
Calculate.co.nz is also partnered with Health Based Building and Premium Homes to promote informed choices that lead to better long-term outcomes for Kiwi households.
Calculate.co.nz is hosted in Auckland via SiteHost new Zealand.
All content on this website, including calculators, tools, source code, and design, is protected under the Copyright Act 1994 (New Zealand). No part of this site may be reproduced, copied, distributed, stored, or used in any form without prior written permission from the owner.
About & trust: Why Calculate is NZ's most comprehensive · By the Numbers · How we compare · Editorial standards · How we keep data current · NZ finance glossary · Research & data · Financial literacy NZ · About · Privacy policy · Terms of use
Reviewed and maintained. Last reviewed 2026-07-02 and checked on a twice-monthly cycle against IRD, RBNZ and Stats NZ. How we keep data current.
© 2026 Calculate.co.nz. All rights reserved. Building free NZ calculators since 2011.