Skip to content
CalcTide logo
Tech

Color Converter

The color #ff0000 is rgb(255, 0, 0) and hsl(0, 100%, 50%). This color converter reads a HEX, RGB, or HSL value and returns the same color in all three formats. Paste a value such as #3b82f6, rgb(59, 130, 246), or hsl(217, 91%, 60%), then read the matching codes and a live swatch.

TechBy

Quick answer

HEX writes each red, green, and blue channel as a two-digit base-16 number from 00 to ff.

What this tells you

  • •HEX writes each red, green, and blue channel as a two-digit base-16 number from 00 to ff.
  • •RGB writes the same three channels as decimal numbers from 0 to 255.
  • •HSL describes a color by its hue in degrees, its saturation as a percent, and its lightness as a percent.
  • •Conversion normalizes output to lowercase 6-digit hex, integer RGB channels, and whole-number HSL components.
  • •RGB input requires three integers from 0 to 255. Decimal, negative, signed-plus, and out-of-range channels are rejected.
  • •HSL input requires integer hue from 0 to 360 and integer saturation and lightness from 0 to 100.
  • •Alpha channels are not parsed, so 4-digit or 8-digit hex, rgba(), and hsla() return no result.

How to Use

  1. 1Type or paste a color in any supported format. The default value is the blue #3b82f6.
  2. 2Use 3- or 6-digit hex such as #f00 or ff0000, integer RGB such as 255,0,0 or rgb(255, 0, 0), or HSL such as 0,100%,50% or hsl(0, 100, 50). A bare HSL triplet needs percent signs so it is not read as RGB.
  3. 3Select Convert to read the HEX, RGB, and HSL versions of the same color.
  4. 4Check the swatch above the results to confirm the color looks right.

How It Works

Formula

RGB channel = base-16 value of each hex pair (00 to ff = 0 to 255). HSL is derived from normalized RGB where lightness = (max + min) / 2

A hex code splits into three pairs, and each pair is a base-16 number for the red, green, and blue channel from 0 to 255. To find HSL, divide each channel by 255, take the largest and smallest of the three, set lightness to their average, derive saturation from their spread, and set hue from which channel is largest. For example #ff0000 has channels 255, 0, 0, so lightness is (1 + 0) / 2 = 0.5, which prints as 50 percent.

Calculation note: values are processed in the order shown above, using the current input units.

Worked Examples

Hex to RGB and HSL

Color#ff0000
Resultrgb(255, 0, 0) and hsl(0, 100%, 50%)

ff is 255, and the two 00 pairs are 0, so the color is pure red. Red sits at hue 0 with full saturation and 50 percent lightness.

RGB to hex

Colorrgb(0, 128, 0)
Result#008000 and hsl(120, 100%, 25%)

0 is 00 and 128 is 80 in base 16, so the hex code is #008000. The low lightness of 25 percent shows this is a dark green.

HSL to hex

Colorhsl(240, 100%, 50%)
Result#0000ff and rgb(0, 0, 255)

Hue 240 with full saturation and 50 percent lightness is pure blue, which is 0000ff in hex.

Short uppercase hex

Color#0F0
Result#00ff00, rgb(0, 255, 0), hsl(120, 100%, 50%)

Input is lowercased and each shorthand digit is doubled. The converter normalizes #0F0 to the full lowercase hex code #00ff00.

Bare HSL with percent signs

Color120,100%,50%
Result#00ff00 and rgb(0, 255, 0)

A percent sign tells the detector to parse the bare comma triplet as HSL. Hue 120 at full saturation and 50% lightness converts to green.

Rounded HSL output

Color#3b82f6
Resultrgb(59, 130, 246) and hsl(217, 91%, 60%)

The hex pairs convert exactly to RGB channels 59, 130, and 246. Hue, saturation, and lightness are rounded to whole output values. Paste hsl(217, 91%, 60%) back in and you get #3c83f6, one step higher on red and green, because the rounded HSL no longer pins down the original channels.

Scenario: Ana's button blue loses its contrast in an HSL round trip

Run 1#0a79c5
Run 2hsl(204, 90%, 41%)
ResultRun 1: rgb(10, 121, 197), hsl(204, 90%, 41%) | Run 2: #0a7bc7, rgb(10, 123, 199)

Ana tuned a button blue, #0a79c5, until white label text on it measured 4.61:1, above the 4.5:1 minimum WCAG 2.2 sets for normal-size text. She converted it here and saved the HSL, hsl(204, 90%, 41%), as a design token. Weeks later a teammate building an email template needed hex, pasted the token into the converter, and got #0a7bc7. Green and blue each moved up 2 steps, the button got slightly lighter, and white text on it now measures 4.496:1. That fails, because WCAG compares the unrounded ratio with 4.5. The fix is to keep the hex or RGB value as the stored color and treat HSL as a view for making adjustments.

HEX to RGB and HSL for CSS named colors, with the HSL round trip

The 16 basic CSS color names plus six common extended ones. The last column is what this converter returns when you paste its own HSL output back in.

CSS nameHEXRGBHSL shownHSL pasted back
black#000000rgb(0, 0, 0)hsl(0, 0%, 0%)#000000, same
white#ffffffrgb(255, 255, 255)hsl(0, 0%, 100%)#ffffff, same
red#ff0000rgb(255, 0, 0)hsl(0, 100%, 50%)#ff0000, same
lime#00ff00rgb(0, 255, 0)hsl(120, 100%, 50%)#00ff00, same
blue#0000ffrgb(0, 0, 255)hsl(240, 100%, 50%)#0000ff, same
yellow#ffff00rgb(255, 255, 0)hsl(60, 100%, 50%)#ffff00, same
aqua (also cyan)#00ffffrgb(0, 255, 255)hsl(180, 100%, 50%)#00ffff, same
fuchsia (also magenta)#ff00ffrgb(255, 0, 255)hsl(300, 100%, 50%)#ff00ff, same
gray#808080rgb(128, 128, 128)hsl(0, 0%, 50%)#808080, same
silver#c0c0c0rgb(192, 192, 192)hsl(0, 0%, 75%)#bfbfbf, drifts
maroon#800000rgb(128, 0, 0)hsl(0, 100%, 25%)#800000, same
green#008000rgb(0, 128, 0)hsl(120, 100%, 25%)#008000, same
navy#000080rgb(0, 0, 128)hsl(240, 100%, 25%)#000080, same
teal#008080rgb(0, 128, 128)hsl(180, 100%, 25%)#008080, same
purple#800080rgb(128, 0, 128)hsl(300, 100%, 25%)#800080, same
olive#808000rgb(128, 128, 0)hsl(60, 100%, 25%)#808000, same
orange#ffa500rgb(255, 165, 0)hsl(39, 100%, 50%)#ffa600, drifts
gold#ffd700rgb(255, 215, 0)hsl(51, 100%, 50%)#ffd900, drifts
crimson#dc143crgb(220, 20, 60)hsl(348, 83%, 47%)#db143c, drifts
dodgerblue#1e90ffrgb(30, 144, 255)hsl(210, 100%, 56%)#1f8fff, drifts
rebeccapurple#663399rgb(102, 51, 153)hsl(270, 50%, 40%)#663399, same
slategray#708090rgb(112, 128, 144)hsl(210, 13%, 50%)#6f8090, drifts

The hex value for each name is defined in CSS Color Module Level 4, section 6.1 (Named Colors), which also says the 16 basic names came from the VGA palette by way of HTML and most of the rest from X11. The RGB, HSL, and pasted-back cells are this converter's own output, checked by running the live formula, and every HSL cell matches exact arithmetic rounded to whole numbers. This tool does not accept color names, so paste the hex code instead.

sRGB, the CSS conversion formulas, and why round trips drift

Hex, rgb(), and hsl() are three spellings of one sRGB color. CSS Color Module Level 4 says sRGB is the default color space for CSS and is used for all of these legacy color forms, citing IEC 61966-2-1:1999 for its definition. That definition fixes the red, green, and blue primaries at the same chromaticities as ITU-R BT.709 HDTV (red at x 0.640, y 0.330, green at 0.300, 0.600, and blue at 0.150, 0.060), a D65 white point, and a transfer curve that is linear up to an encoded value of 0.04045 and follows a 2.4 power with a 0.055 offset above it. A hex code stores the encoded values, not light intensity, and every conversion on this page works on those encoded values. The curve only matters when you need physical light, as in the contrast math further down.

Section 5.2 of CSS Color 4 defines #rrggbb as three base-16 pairs, where 00 is the minimum and ff, or 255, is the maximum. That gives each channel 256 levels, and six digits give 256 × 256 × 256 = 16,777,216 colors. The 3-digit form doubles each digit, so #123 is #112233, and the spec notes it reaches only 4,096 colors. The 4- and 8-digit forms add an alpha pair, which this tool rejects. Hex to RGB is exact in both directions because it only changes the base.

HSL rearranges the same encoded values. With each channel scaled to 0 to 1, lightness is (max + min) / 2, saturation is (max - lightness) / min(lightness, 1 - lightness), and hue is the 60-degree sector of the largest channel plus how far the other two pull it. CSS Color 4 publishes sample code for both directions in sections 7.1 and 7.2. This tool's sector method is algebraically the same, though the two can land on different sides of an exact half because of floating point. Because lightness is a plain average of encoded channels, the spec warns that it does not track how light a color looks. Yellow and blue are both hsl lightness 50%, yet their WCAG relative luminance is 0.9278 and 0.0722.

Whole-number HSL is coarser than hex. The tool prints hue in whole degrees and saturation and lightness in whole percents, which allows 361 × 101 × 101 = 3,682,561 HSL inputs. Running every one of them through the converter reaches only 2,037,749 distinct hex codes, 12.1 percent of the 16,777,216. Going the other way, 1,775,549 hex colors (10.6 percent) come back unchanged after hex to HSL to hex. For 54.4 percent the largest channel change is 1, for 32.1 percent it is 2, and the worst 108 colors move by 5. CSS Color 4 asks browsers to keep sRGB values precise enough to round-trip 8-bit channels and to round toward +∞ rather than truncate, a bar whole-number HSL cannot meet. This tool rounds exact halves up the same way, so in hsl(0, 100%, 5%), whose red channel is exactly 25.5, the result is #1a0000. Keep hex or RGB as the stored value.

Two limits sit outside the format math. The first is gamut. Hex, rgb(), and hsl() can only name colors inside sRGB. CSS Color 4 adds color(display-p3 r g b) for the wider Display P3 space, whose red and green primaries (x 0.680, y 0.320 and x 0.265, y 0.690) sit outside the sRGB triangle, and it notes that modern displays, laptop screens, and phone screens can show all or nearly all of that space. A Display P3 color outside sRGB has no exact hex code, and bringing it into sRGB takes gamut mapping, which this tool does not do. The second is contrast. WCAG 2.2 Success Criterion 1.4.3 asks for 4.5:1 between normal text and its background and 3:1 for large text, using relative luminance computed from linearized channels as 0.2126 R + 0.7152 G + 0.0722 B. White text on this page's default #3b82f6 measures 3.68:1, fine for large headings but short of 4.5:1 for body copy.

Blend two hex colors with the color mixer

Common mistakes

  • Leaving off the leading hash is fine, but a stray invalid character like a letter past f makes the hex code fail.
  • Mixing up 3-digit and 6-digit hex. The 3-digit form #f00 doubles each digit to #ff0000, so #f00 and #ff0000 are the same color.
  • Entering a bare HSL triplet without percent signs. The detector reads 0,100,50 as RGB, while hsl(0, 100, 50) is explicitly HSL.
  • Entering decimal RGB or HSL components even though this parser accepts integers only.
  • Expecting 4- or 8-digit hex and rgba or hsla transparency to work. Alpha formats are unsupported.
  • Treating the swatch as a print proof or assuming every display renders the same sRGB code identically.
  • Choosing text and background colors without checking contrast and non-color cues for accessibility.

Embed this calculator on your site

Paste this code where you want the calculator to appear. It is responsive, mobile-friendly, resizes automatically, and is free to use as long as the credit line stays in place.

<script src="https://calctide.com/embed.js" data-tool="color-converter" async></script> <p style="font-size:12px;margin:4px 0 0">Color Converter by <a href="https://calctide.com/tech/color-converter/">CalcTide</a></p>

Preview the embed at /embed/color-converter/.

Frequently Asked Questions

Split the hex code into three pairs and read each pair as a base-16 number from 0 to 255. For #ff0000 the pairs ff, 00, and 00 give rgb(255, 0, 0). Paste any hex code above to do this instantly.
Write each of the red, green, and blue channels as a two-digit base-16 number and join them after a hash. rgb(0, 128, 0) becomes #008000 because 0 is 00 and 128 is 80.
HSL is a way to describe a color by its hue, saturation, and lightness. Hue is an angle from 0 to 360 degrees that picks the base color, saturation is how vivid it is from 0 to 100 percent, and lightness runs from black at 0 percent through the full color at 50 percent to white at 100 percent.
Yes, #fff and #ffffff are the same color, white. The 3-digit form is shorthand where each digit is doubled, so f becomes ff for every channel.
No, this converter handles solid colors only. Inputs with an alpha channel, such as 4- or 8-digit hex, rgba(), or hsla(), return no result. Convert the base color here, then add your own alpha value in rgba or hsla afterward.
The hex code #3b82f6 is rgb(59, 130, 246) and hsl(217, 91%, 60%), a medium blue. The channels 3b, 82, and f6 are 59, 130, and 246 in decimal.
Wrapped hsl() input accepts integer saturation and lightness with or without percent signs. A bare comma triplet needs a percent sign so the detector treats it as HSL rather than RGB.
No. This parser accepts integer channels from 0 to 255 only. A decimal channel or a value outside that range returns no result.
No. Alpha and opacity formats are unsupported. Enter the solid base color as 3- or 6-digit hex, RGB, or HSL.
Because HSL output uses whole degrees and whole percentages, which cannot pin down every 8-bit channel. #3b82f6 converts to hsl(217, 91%, 60%), and that HSL converts back to #3c83f6. Only about 10.6 percent of the 16,777,216 hex colors come back unchanged.
No. Format conversion says nothing about contrast. Test the foreground and background pair against the accessibility criteria that apply, such as the 4.5:1 minimum for normal text in WCAG 2.2. White text on #3b82f6 measures 3.68:1, so it passes only for large text.
A 6-digit hex code can represent 16,777,216 colors, 256 levels each for red, green, and blue. The 3-digit shorthand reaches only 4,096 because each digit is doubled, so #123 can only mean #112233.
It estimates color converter outputs using the visible inputs and formula assumptions on this page.

Explore More in Tech