Hex Color Converter
Enter red, green and blue values (0 to 255) to see the hex code and the HSL representation.
What the converter returns
Enter a red, green and blue value between 0 and 255 and the tool returns the six-digit hex code and the HSL equivalent. The defaults 52, 152, 219 produce #3498DB and 204, 70%, 53%. Both outputs describe the same color: one as three raw channel values, the other as hue, saturation and lightness. Nothing is rounded in the hex path; only the HSL display is rounded to whole numbers.
From one channel to two hex digits
Each channel is an 8-bit value, so it has 256 possible levels from 0 to 255. Base 16 writes that range with exactly two digits, where the first digit is the high nibble (16s place) and the second is the low nibble (1s place). A channel value v becomes two characters: the whole part of v ÷ 16, then the remainder.
The defaults show the arithmetic. Red 52 = 3 × 16 + 4, which is 34. Green 152 = 9 × 16 + 8, which is 98. Blue 219 = 13 × 16 + 11, and 13 is D while 11 is B, so the pair is DB. Joined in order R, G, B, the code is #3498DB.
Nothing about the color changes when you convert. Hex is a compact transcription of the same three bytes, which is why #3498DB and rgb(52, 152, 219) are interchangeable in CSS and why a hex value always has exactly six digits for an opaque color.
Why the digits sometimes look single
A channel of 10 is 0A, not just A. Dropping the leading zero shifts every following digit and changes the color, so the converter always pads to two characters. This is why pure black is #000000 and not #000, and why a three-digit shorthand such as #fff is only a compressed form where each digit is doubled.
Worked example from RGB to HSL
Normalise each channel by dividing by 255: red 0.2039, green 0.5961, blue 0.8588. The maximum is blue and the minimum is red, so lightness is (0.8588 + 0.2039) ÷ 2 = 0.5314, or 53%.
The range d = max − min = 0.6549. Because lightness is above 0.5, saturation uses d ÷ (2 − max − min) = 0.6549 ÷ 0.9373 = 0.6988, or 70%. Hue is measured from the dominant channel: with blue largest, h = (r − g) ÷ d + 4 = −0.599 + 4 = 3.401, and 3.401 ÷ 6 × 360 = 204 degrees.
That 204 degrees sits in the blue-cyan sector, which matches the eye: #3498DB is the familiar flat-UI blue, not a pure blue at 240 degrees. The 70% saturation keeps it from looking grey, and the 53% lightness puts it mid-range so white text remains readable on top.
| Color | RGB | Hex | HSL |
|---|---|---|---|
| Red | 255, 0, 0 | #FF0000 | 0, 100%, 50% |
| Yellow | 255, 255, 0 | #FFFF00 | 60, 100%, 50% |
| Green | 0, 255, 0 | #00FF00 | 120, 100%, 50% |
| Blue | 0, 0, 255 | #0000FF | 240, 100%, 50% |
| Default | 52, 152, 219 | #3498DB | 204, 70%, 53% |
| Mid grey | 128, 128, 128 | #808080 | 0, 0%, 50% |
| White | 255, 255, 255 | #FFFFFF | 0, 0%, 100% |
| Black | 0, 0, 0 | #000000 | 0, 0%, 0% |
The four corners of the cube make the pattern clear. Pure primaries sit at 100% saturation and 50% lightness, with hue 120 degrees apart. Any grey has 0% saturation because all three channels are equal, and black and white differ only in lightness at 0% and 100%.
What each HSL channel controls
- Hue runs 0–360 degrees around the color wheel: 0 red, 60 yellow, 120 green, 180 cyan, 240 blue, 300 magenta
- Saturation runs 0–100%: at 0 the color collapses to grey at the same lightness
- Lightness runs 0–100%: 0 is black and 100 is white regardless of hue or saturation
- Two colors with the same hue and lightness but different saturation read as vivid versus muted
Designers reach for HSL because those three dials behave predictably. To build a hover state you drop lightness by 8 percentage points; to build a disabled state you drop saturation by 40. Doing the same in RGB means recalculating three channels that all move at once.
Common mistakes
- Dropping a leading zero, turning a channel of 10 into A instead of 0A and shifting the whole code
- Reading #3498DB as three pairs in the wrong order: it is 34, 98, DB, not 3, 498, DB
- Assuming hex is case-sensitive: #3498db and #3498DB are the same color
- Mixing an alpha channel into the six-digit form: eight-digit hex adds AA at the end, not the start
- Expecting HSL to round-trip exactly, since the display rounds to integers and can drift by one degree
Gamma and display differences
Two screens can show #3498DB differently even though the code is identical, because channel values are device-independent inputs to a color-managed pipeline rather than literal light measurements. A wide-gamut display may render the blue more saturated than an sRGB panel. The code is exact; the appearance is not guaranteed, which is why print work uses CMYK profiles instead of hex.
Clamping and rounding
The inputs are rounded to the nearest integer and clamped to 0–255 in both directions, so 300 becomes 255 and −4 becomes 0. The hex path uses integer bit shifts, which cannot overflow at this width. The HSL path works in floating point and rounds each of the three outputs for display, so a color sitting exactly on a .5 boundary can show a value one degree off from a stricter converter.
Frequently asked questions
How do I convert RGB to hex?
Write each channel in base 16 and pad it to two digits. 255, 0, 0 becomes FF0000, and 52, 152, 219 becomes 3498DB.
What is the difference between RGB and HSL?
RGB names the three channel levels directly, while HSL names hue, saturation and lightness. #3498DB is rgb(52, 152, 219) and hsl(204, 70%, 53%) at the same time.
Why are hex codes six digits?
Two digits per channel across red, green and blue. Two hex digits hold 256 values, which matches the 0–255 range of an 8-bit channel exactly.
What is RGB 52, 152, 219 in hex?
3498DB. Red 52 is 34, green 152 is 98 and blue 219 is DB, so the full code is #3498DB, the default of this calculator.
Can I shorten #3498DB to three digits?
No. Three-digit shorthand only works when each pair repeats a digit, as in #FFCC00 becoming #FC0. The pairs 34, 98 and DB do not repeat, so the short form would change the color.
Why is saturation 0% for grey?
Grey has equal red, green and blue channels, so the maximum minus minimum is zero. With no channel spread there is no hue to saturate, which is why #808080 reports 0, 0%, 50%.
Is hex case-sensitive?
No. #3498db and #3498DB are identical; this tool prints uppercase by convention. Case only matters when a system compares the string literally rather than parsing it as a color.
How do I add transparency to a hex color?
Append a two-digit alpha pair, making eight digits. #3498DB at 50% opacity is #3498DB80, where 80 hex equals 128 of 255.
Why does HSL say 204 degrees instead of 240 for this blue?
Pure blue is 240 degrees, but #3498DB leans toward cyan because green is 152 against a blue of 219. The hue formula gives (r − g) ÷ d + 4, which lands at 204 degrees.
Method and sources
- Hex color = two base-16 digits per RGB channel.