๐ŸŽจ Converting Between HEX, RGB, and HSL Color Codes

The difference between the three formats

Work with colors in CSS or a design tool for long enough and you'll run into all three notations โ€” #3b82f6, rgb(59, 130, 246), and hsl(217, 91%, 60%). This article covers what HEX, RGB, and HSL each actually represent, when one is more convenient than the others, and how to convert a single color across all three.

What HEX, RGB, and HSL Each Represent

HEX (hexadecimal) notation takes the form #RRGGBB, where the red, green, and blue channels are each written as a two-digit base-16 number ranging from 00 to FF (0โ€“255 in decimal). For example, #ffffff is white and #000000 is black. RGB notation is the exact same three channel values written as plain decimal numbers, like rgb(255, 255, 255) โ€” it carries identical information to HEX, just in a different base. HSL, by contrast, describes a color along three completely different axes: hue (a position on a 0โ€“360ยฐ color wheel), saturation (0โ€“100%, how vivid the color is), and lightness (0โ€“100%, how bright it is). Where HEX and RGB mix the three primary colors of light directly, HSL is closer to how people actually perceive color โ€” it separates "which hue" from "how bright and how vivid."

When Each Notation Is Useful

HEX is the shortest of the three and is treated as the de facto standard across CSS, design tools, and color palettes, which makes it the most common choice for setting colors in a stylesheet or sharing a color code with someone else. RGB keeps the R, G, and B channels as plain numbers, which makes it convenient for code that needs to do direct arithmetic on color values channel by channel โ€” image processing, canvas pixel manipulation, and the like. HSL separates saturation and lightness into their own channels, so intuitive adjustments โ€” "keep the same hue but make it brighter," or "desaturate to tone it down" โ€” only require changing a single number. For example, instead of eyeballing a new HEX value for a button's hover state, lowering HSL's lightness (L) by a few percent gives you a precisely darker version of the exact same hue.

A Worked Conversion Example

Take the blue #3b82f6 as an example. Splitting the HEX value by channel: 3b (hex) = 59, 82 (hex) = 130, f6 (hex) = 246, so in RGB that's rgb(59, 130, 246). To convert further to HSL, normalize R, G, and B to a 0โ€“1 range (0.231, 0.510, 0.965), then compute lightness as the average of the max and min values, saturation from the difference between max and min, and the hue angle from which channel holds the maximum. Working through that math, #3b82f6 comes out to hsl(217, 91%, 60%) โ€” a hue of 217ยฐ (blue), 91% saturation (vivid), and 60% lightness (a bit brighter than mid-tone). All three notations point to exactly the same color, but computing the channels by hand is tedious and easy to get wrong. A tool that shows HEX, RGB, and HSL values simultaneously for a color you pick lets you check conversions like this far faster and more reliably.

Common colors in HEX, RGB & HSL

A quick reference of frequently used colors in all three notations (converted and verified with node). Each row is the same color in different notations, so the values correspond exactly.

ColorHEXRGBHSL
Black#000000rgb(0, 0, 0)hsl(0, 0%, 0%)
White#FFFFFFrgb(255, 255, 255)hsl(0, 0%, 100%)
Red#FF0000rgb(255, 0, 0)hsl(0, 100%, 50%)
Green#008000rgb(0, 128, 0)hsl(120, 100%, 25%)
Blue#0000FFrgb(0, 0, 255)hsl(240, 100%, 50%)
Yellow#FFFF00rgb(255, 255, 0)hsl(60, 100%, 50%)
Cyan#00FFFFrgb(0, 255, 255)hsl(180, 100%, 50%)
Magenta#FF00FFrgb(255, 0, 255)hsl(300, 100%, 50%)
Gray#808080rgb(128, 128, 128)hsl(0, 0%, 50%)
Silver#C0C0C0rgb(192, 192, 192)hsl(0, 0%, 75%)
Orange#FFA500rgb(255, 165, 0)hsl(39, 100%, 50%)
Purple#800080rgb(128, 0, 128)hsl(300, 100%, 25%)
Navy#000080rgb(0, 0, 128)hsl(240, 100%, 25%)
Teal#008080rgb(0, 128, 128)hsl(180, 100%, 25%)

In HSL, H (hue) ranges 0โ€“360ยฐ, while S (saturation) and L (lightness) range 0โ€“100%. Achromatic colors (black, white, gray) have 0% saturation, so their hue value is not meaningful.

๐ŸŽจ Try it yourself with the tool

Converting Between HEX, RGB, and HSL Color Codes โ€” The difference between the three formats

More Guides

๐Ÿ”
How to Find a Domain's IP Address
Find the real server IP a domain points to
๐Ÿ›ฐ๏ธ
How to Check DNS Propagation (What Is TTL?)
Understand TTL and check propagation after a nameserver change
๐Ÿ“ก
The Easiest Way to Find Your IP Address
Public vs private IP, and how to check yours
๐Ÿ“
CIDR Notation and How to Calculate a Subnet Mask
Convert CIDR notation like /24 into a subnet mask
๐Ÿฉบ
How to Check an SSL Certificate's Expiration Date
Check a certificate's expiry without opening a browser
๐Ÿชช
Understanding JWT Structure and How to Decode It
The Header, Payload & Signature โ€” explained
๐Ÿ—๏ธ
How to Create an Apache .htpasswd File for Basic Auth
Generate an APR1-MD5 hashed .htpasswd file
๐Ÿ”‘
What Makes a Strong Password (and How to Generate One)
Length, character sets & entropy explained
๐Ÿ”
What Is Base64 Encoding and When to Use It
Why it's used in email attachments & data URIs
๐Ÿ“˜
Using a JSON Formatter to Read API Responses
Turn minified JSON into something readable
๐Ÿ—“๏ธ
How to Convert a Unix Timestamp to a Date
Turn seconds-since-1970 into a readable date
๐Ÿ—ƒ๏ธ
How to Format Messy SQL Queries
Break a one-line SQL statement into readable clauses
๐Ÿ” 
camelCase, snake_case & Other Naming Conventions
When to use each naming style
๐Ÿ†š
How to Compare Two Text Files (Diff Checker)
Quickly spot differences between two versions
๐Ÿ”ค
What Is Punycode?
The encoding that makes internationalized domain names (IDN) safe for ASCII-only DNS.
๐Ÿ”€
Converting IPv4 to IPv6
What that ::ffff:192.168.1.1 entry in your logs actually is.
๐Ÿ•ธ๏ธ
Extracting Domains From Text
Pulling just the domains out of mixed text like logs or emails.
๐Ÿšช
Opening Multiple URLs at Once
Stop clicking through your daily site list one at a time.
๐Ÿ“ฎ
Verifying an Email Address
What format checks and MX records can confirm โ€” and what they can't.
๐Ÿ“‹
Inspecting HTTP Response Headers
Cache policy, server details, and compression, all from one set of headers.
๐Ÿ›ก๏ธ
Checking Security Headers
HSTS, CSP, X-Frame-Options โ€” and the risk of skipping each one.
๐Ÿ“‡
Looking Up Domain Info With WHOIS/RDAP
Who registered it, when, and when it expires.
๐Ÿ“
Finding a Rough Location From an IP
How it works, how accurate it really is, and why a VPN changes the answer.
๐Ÿ–ผ๏ธ
Checking OGP Meta Tags
What to check when a share card on social or chat apps looks wrong.
๐Ÿ“‘
Checking Heading Structure (h1โ€“h6)
The foundation of SEO and accessibility โ€” a clean heading hierarchy.
๐Ÿท๏ธ
Checking TITLE & META Tags
The tags that decide how a page appears in search results.
#๏ธโƒฃ
What Is a Hash Function?
Which hash to use when, and what "can't be reversed" actually means.
๐Ÿ“ฑ
How QR Codes Work
Why they still scan when partly covered, and how QR phishing works.
๐Ÿ”
Reading SSL Certificate Fields
What CN, SAN, issuer, and validity period each mean.
๐Ÿ“œ
What Is a CSR?
Why getting an SSL certificate starts with generating a CSR.
โ™ป๏ธ
PEM vs DER Certificate Format
Why the same certificate sometimes needs to be re-encoded.
๐Ÿค
When Cert and Key Don't Match
How the check works, and what usually causes a mismatch.
๐Ÿช„
Using a Self-Signed SSL Certificate
Fine for testing and dev โ€” never for production. Here's why.
๐Ÿ”‘
HTTP Basic vs Bearer Auth
How the Authorization header value is built, and which scheme fits which case.
๐ŸŽซ
Generating Secure Random Tokens
How long should an API key or session secret be, and in what format?
๐Ÿ”’
Encrypting Config Values With Jasypt
How the ENC(...) value in application.properties actually works.
๐Ÿงฉ
What Is JSON String Escaping?
Safely putting text with quotes or newlines into a JSON value.
โœจ
Formatting vs Minifying JS/CSS
Format while you work, minify when you ship โ€” and why they pull in opposite directions.
โœ‚๏ธ
How Far Minification Should Go
Stripping whitespace is always safe โ€” renaming variables can break things.
๐Ÿงฝ
Why HTML Indentation Matters
You can't spot a mistake in a structure you can't see.
๐Ÿงน
When to Reformat XML
Seeing the element nesting in a single dense line of XML.
๐Ÿ”ฃ
What Are HTML Entities?
Showing literal <, >, and & characters on the page.
๐Ÿ“Š
Turning a Spreadsheet Into an HTML Table
From copy-paste straight to HTML โ€” no tags typed by hand.
โ›“๏ธ
Extracting Links From HTML
Pulling out every href and src value at once.
๐Ÿ˜
The Limits of PHP/MySQL Syntax Checkers
What a bracket/quote check can confirm โ€” and what it can't.
๐Ÿ—„๏ธ
When a MySQL Pairing Check Helps
Catching mistakes in long subqueries and dynamically built queries.
๐Ÿ”
Common HTML5 Validation Errors
Mismatched tags, duplicate ids, missing alt โ€” why each one matters.
โœ๏ธ
When to Use a Visual HTML Editor
Where WYSIWYG wins, and where writing code by hand wins.
๐Ÿ“
Why Markdown Preview Matters
What the raw code hides that the rendered result reveals.
๐Ÿ”—
What Is URL Percent-Encoding?
Why a space or non-ASCII character turns into something like %20 or %EC%95%88.
โœ๏ธ
Find & Replace With Regex
For replacements a plain search can't do.
โ†•๏ธ
What to Know Before Sorting a List
Why alphabetical and numeric order don't behave the same way.
๐Ÿ“ง
Extracting Emails From Text
The regex pattern, and the false positives that trip people up.
๐Ÿ”ข
Why Character Count โ‰  Byte Count
Why one Korean character can take up 3 bytes.
๐Ÿ”ค
What Are Fullwidth and Halfwidth Characters?
Why something that looks like a digit doesn't match in search.
๐Ÿˆš
What Is a Unicode Code Point?
The unique number behind every character, and how to read U+XXXX.
๐Ÿ”Ÿ
How Text Converts to Numbers
Decimal, hex, binary โ€” the same value, written three ways.
๐Ÿงพ
UTF-8 Byte Encoding Basics
Why English takes 1 byte and Korean takes 3.
0๏ธโƒฃ
How Text Becomes 0s and 1s
What a bit is, and how text turns into bits.
๐Ÿ”ก
How ASCII Art Is Made
Drawing large letters out of nothing but characters.