Color Picker and Contrast Checker
White text on #2563EB reaches 5.17 to 1 and passes WCAG AA for body text. Black text on the same blue sits at 4.06 to 1 and passes only for large text, and the code converts to rgb(37, 99, 235). Check both numbers before putting small text on a colored button.
| HEX | |
| RGB | |
| HSL | |
| Relative luminance | |
| Contrast with white text | |
| Contrast with black text | |
| Better text color | |
| Better text color passes AA body (4.5 to 1) | |
| Better text color passes AA large (3 to 1) |
Contrast follows the WCAG 2.1 relative luminance formula. All calculations run in your browser, and nothing you type is uploaded or stored.
Type a HEX code or set hue, saturation and lightness to see the same color in all three formats, plus its contrast ratio against white and black text.
Key takeaways
- HEX pairs run 00 to FF, giving 16,777,216 colors
- #2563EB is rgb(37, 99, 235) and hsl(221, 83%, 53%)
- AA needs 4.5 to 1 for body text and 3 to 1 for large text
- White on #2563EB measures 5.17 to 1
- White on #059669 drops to 3.77 to 1 and fails AA
On this page
One color, three sets of numbers
A screen pixel is three small lights, one red, one green and one blue. Every color you see is a mix of those three, and every color format is a way of writing down how much of each light to turn on. HEX, RGB and HSL all describe the same sRGB color space, so any of them can be converted into the others without losing anything.
The differences are about convenience. HEX is compact and lives in stylesheets and design files. RGB matches how the hardware works. HSL matches how people think about color, because it separates the hue from how light or dark the color is. A designer who needs a darker shade of the same blue can drop the lightness in HSL and keep the hue, which is awkward in HEX.
This page takes one color and shows it three ways, then checks the contrast against white and black text. That last number decides whether the color can carry text at all, and it is the step most palettes skip.
HEX codes in plain English
A HEX code is six hexadecimal digits in three pairs, written with a hash in front. The pairs are red, green and blue, in that order. Each pair runs from 00 to FF, which is 0 to 255 in decimal, so there are 256 levels per channel and 16,777,216 possible colors in a six digit code.
Hexadecimal is base 16, so the digits run 0 to 9 and then A to F for 10 to 15. A pair like 25 is 2 times 16 plus 5, which is 37. A pair like EB is 14 times 16 plus 11, which is 235. That is the whole conversion, and it is why #2563EB is the same as rgb(37, 99, 235).
Three digit codes are shorthand. Each digit is doubled, so #26E becomes #2266EE. That only works when both digits in a pair match, which limits the shorthand to 4,096 colors. Eight digit codes add an alpha pair at the end, so #2563EBCC is the same blue at 80% opacity.
| Format | Example | What each value means | Best for |
|---|---|---|---|
| HEX | #2563EB | Three pairs, 00 to FF | CSS, design files, brand guides |
| HEX with alpha | #2563EBCC | Adds an opacity pair | Overlays and shadows |
| RGB | rgb(37, 99, 235) | Three channels, 0 to 255 | Canvas, SVG, image code |
| HSL | hsl(221, 83%, 53%) | Hue angle, saturation, lightness | Building palettes and themes |
Case does not matter. #2563eb and #2563EB are the same color, and browsers treat them as identical. Most style guides settle on uppercase for readability in long lists, and either is fine as long as the file is consistent.
RGB: the numbers your screen uses
RGB writes the three channel values directly, each from 0 to 255. Zero means the light is off and 255 means full power, so rgb(0, 0, 0) is black and rgb(255, 255, 255) is white. Mixing is additive: red plus green gives yellow, and all three at full power give white.
The range stops at 255 because each channel is stored in 8 bits, and 8 bits hold 256 values starting at zero. Modern CSS also accepts percentages, so rgb(14.5% 38.8% 92.2%) is the same color as rgb(37, 99, 235), and it accepts a fourth value for alpha: rgb(37 99 235 / 0.8).
RGB is the format to reach for when you are computing. Blending two colors, darkening by a fixed amount, or averaging a palette all work on channel values. It is the least friendly format to read, because rgb(37, 99, 235) does not tell you that the color is a medium blue until you decode it.
One quirk is worth knowing. The sRGB values are not linear light. A value of 128 is not half the brightness of 255, it is closer to a fifth, because the encoding bends the curve to match how the eye works. That is why the contrast formula has to linearize each channel before it does any math.
HSL and the color wheel
HSL stands for hue, saturation and lightness. Hue is an angle on the color wheel from 0 to 360 degrees. Saturation is how far the color sits from gray, from 0% for a pure gray to 100% for the most vivid version. Lightness runs from 0% for black through 50% for the pure hue to 100% for white.
The angle is the useful part. Red sits at 0, yellow at 60, green at 120, cyan at 180, blue at 240 and magenta at 300. Complementary colors sit 180 degrees apart, and a triad sits 120 degrees apart, which makes it easy to build a scheme that is not random.
| Hue angle | Color family | Common use |
|---|---|---|
| 0 to 15 | Red | Errors, sale tags, warnings |
| 30 to 45 | Orange and amber | Caution, highlights |
| 50 to 65 | Yellow | Attention, but poor on white |
| 90 to 150 | Green | Success, confirmations |
| 170 to 200 | Cyan and teal | Info, calm surfaces |
| 210 to 250 | Blue | Links, primary buttons |
| 260 to 290 | Violet | Accents, premium themes |
| 300 to 340 | Magenta and pink | Playful accents |
Lightness is where HSL earns its place. Take #2563EB, which is hsl(221, 83%, 53%). Drop the lightness to 35% and you get a dark blue that keeps the same hue and saturation, which is exactly what a hover state needs. In HEX you would be guessing at three channel values to get the same shift.
Saturation behaves in a way that surprises people. At 100% lightness every hue becomes white, and at 0% lightness every hue becomes black, so the hue angle stops mattering at the ends of the scale. The vivid colors live near 50% lightness, and most brand palettes sit between 40% and 60%.
Converting between the three formats
The conversion is arithmetic, not magic. Take #2563EB and walk it through.
- HEX to RGB: split into 25, 63 and EB. 25 is 37, 63 is 99, EB is 235. The result is rgb(37, 99, 235).
- RGB to HSL, lightness: the largest channel is 235 and the smallest is 37. Lightness is the average of the two divided by 255, so (235 + 37) / 2 / 255 = 0.533, or 53%.
- RGB to HSL, saturation: the spread is 235 minus 37, which is 198. Divide by 255 to get 0.776, then divide by 1 minus the distance of lightness from 0.5 doubled, which is 0.933. The result is 0.832, or 83%.
- RGB to HSL, hue: blue is the largest channel, so the hue starts at 240 degrees and shifts by the red and green values. The result is 221 degrees.
- Result: hsl(221, 83%, 53%).
Going the other way, HSL to RGB, uses the same formulas in reverse. Convert the hue to a position on a 0 to 1 scale, build the chroma from saturation and lightness, then add the same offset to each channel. A spreadsheet or a few lines of code handle it faster than a person can, which is why the calculator on this page exists.
#2563EB is exactly hsl(221.2, 83.2%, 53.3%). Round those to whole numbers, type 221, 83 and 53 back in, and the conversion returns #2463EB, one step off on the red channel. That drift is normal and it is why the HEX value should stay the source of truth while the HSL numbers act as a working copy.
Contrast and readability
Contrast is the difference in brightness between text and its background, written as a ratio from 1 to 1 up to 21 to 1. The W3C's WCAG 2.1 guidance on contrast sets the thresholds that most accessibility rules, including Section 508 in the US, build on.
| Text size | AA minimum | AAA minimum | Typical use |
|---|---|---|---|
| Normal, under 18 pt | 4.5 to 1 | 7 to 1 | Body copy, labels, captions |
| Large, 18 pt or 14 pt bold | 3 to 1 | 4.5 to 1 | Headlines, buttons, hero text |
| Icons and borders | 3 to 1 | Not defined | Input outlines, focus rings |
The ratio comes from relative luminance, which weights the channels by how much each one contributes to perceived brightness: 0.2126 for red, 0.7152 for green and 0.0722 for blue. Green carries most of the weight, which is why a pure green at rgb(0, 255, 0) is far brighter than a pure blue at rgb(0, 0, 255) even though both are full power.
Run the numbers on #2563EB and the luminance is 0.153. Against white the ratio is (1.0 + 0.05) / (0.153 + 0.05) = 5.17 to 1, which passes AA for body text. Against black the ratio is (0.153 + 0.05) / 0.05 = 4.06 to 1, which fails AA for body text and passes only for large text. White is the right text color on that blue.
Try #059669, a medium green, and the answer flips. Its luminance is 0.229, so white text sits at 3.77 to 1 and black text at 5.57 to 1. White on that green looks fine on a bright monitor and fails in daylight. That gap between what looks fine and what measures fine is the reason to check.
Picking colors that hold up
A palette that works in a design tool can fall apart in a browser, on a phone, outdoors, or for a reader with low vision. A few habits catch most of the problems before launch.
Test in grayscale. Convert the screen to gray and check that the hierarchy still reads. If the primary button and the disabled button become the same gray, the palette is leaning on hue to carry meaning that hue cannot carry for everyone.
Do not use hue alone. Error and success states need an icon or a label as well as a color. Roughly 1 in 12 men has some form of color vision deficiency, according to Colour Blind Awareness, and red against green is the most common confusion.
Check the small sizes. A color that passes at 24 pixels can fail at 12 pixels, because thin strokes lose contrast at the edges. Run the check on the smallest size the color appears at, not the largest.
Keep a floor. Pick a body text color that clears 7 to 1 against the background and you have room to move. Pick one at 4.6 to 1 and any change to the background, a tinted section or a hover state, drops it below the line.
Limit the palette. One primary, one accent, three neutrals and a set of state colors covers most interfaces. Every extra hue is another contrast pair to check and another chance for two colors to look the same on a cheap screen.
Frequently asked questions
What does a HEX color code mean?
It is three pairs of hexadecimal digits, one pair each for red, green and blue. #2563EB means red 25, green 63 and blue EB, which in decimal is 37, 99 and 235. Each pair runs from 00 to FF, so there are 256 levels per channel.
How many colors can a HEX code describe?
16,777,216. That is 256 to the power of 3, one value for each of the three channels. An eight digit code with an alpha pair adds 256 transparency levels on top of that.
How do I convert HEX to RGB?
Split the code into three pairs and read each pair as base 16. #2563EB splits into 25, 63 and EB. 25 is 2 x 16 + 5 = 37, 63 is 6 x 16 + 3 = 99, and EB is 14 x 16 + 11 = 235, so the RGB value is 37, 99, 235.
What is HSL and why use it?
HSL describes a color as a hue angle from 0 to 360, a saturation from 0 to 100% and a lightness from 0 to 100%. #2563EB is hsl(221, 83%, 53%). It is easier to build a palette in HSL because you can hold the hue and move lightness.
What is the contrast ratio for WCAG AA?
4.5 to 1 for normal text and 3 to 1 for large text, which WCAG 2.1 defines as 18 point or 14 point bold and up. Level AAA raises those to 7 to 1 and 4.5 to 1.
Does white or black text work better on #2563EB?
White. White on #2563EB is 5.17 to 1, which passes AA for body text. Black on the same blue is 4.06 to 1, which passes only for large text at 18 point or 14 point bold.
What contrast ratio does #059669 need for white text?
White on #059669 is 3.77 to 1, so it fails AA for body text and passes only for large text. Black on the same green is 5.57 to 1, so black is the better choice for small labels.
Why does a 3 digit HEX code work?
Each digit is doubled. #26E expands to #2266EE, so red becomes 22, green becomes 66 and blue becomes EE. The shorthand only covers colors where both digits in a pair match.
How is relative luminance calculated?
Each channel is divided by 255, linearized with a 2.4 power curve, then weighted 0.2126 for red, 0.7152 for green and 0.0722 for blue. The weights follow the eye's sensitivity, which is why green looks far brighter than blue at the same value.
What is the highest possible contrast ratio?
21 to 1, for pure black text on pure white. Pure white on pure black is the same 21 to 1. Any pair of colors that are not black and white lands below that ceiling.
Can I use HSL in CSS directly?
Yes. hsl(221 83% 53%) is valid CSS, and modern browsers also accept hsl(221deg 83% 53% / 0.8) for a color with 80% opacity. HEX, RGB and HSL all describe the same sRGB color space.
Why do the same numbers look different on two screens?
Screens differ in gamut, brightness and calibration. A color at 5.17 to 1 contrast on a calibrated monitor can look flatter on a cheap laptop at 60% brightness, so treat contrast as a floor rather than a guarantee.
What is the 60-30-10 rule for color?
Use a dominant color for about 60% of the surface, a secondary for 30% and an accent for 10%. The ratio keeps a page from looking striped and gives the accent room to stand out at small sizes.
How do I check a color for colorblind users?
Run it through a deuteranopia simulation and check that the contrast between elements survives. About 1 in 12 men has some color vision deficiency, so never rely on hue alone to carry meaning.
Spotted a wrong number or a broken result?
More Design tools
Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.