How to Convert Colors Between Hex, RGB, and HSL
Color shows up in many formats on the web. A designer may hand you a hex code. A developer may ask for RGB values. A style sheet may use HSL because it is easier to adjust. All three formats can describe the same color, but they do not look the same on the page. If you guess the conversion, you can end up with a slightly different shade, a button that no longer matches the brand, or a background that is too light or too dark.
This guide explains how to convert colors between hex, RGB, and HSL in plain language. You will learn what each format means, how the parts of each format fit together, and a reliable step-by-step method that uses a converter instead of your eyes. You will see a complete worked example for the color #FF5733, learn how HSL helps you make lighter, darker, and muted versions, and understand the limits of conversion.
What Hex, RGB, and HSL Mean
Hex is a short way to write red, green, and blue values in base sixteen. A hex color looks like #FF5733. The first two characters after the hash stand for red, the next two stand for green, and the last two stand for blue. Each pair can range from 00 to FF. In decimal, that range is 0 to 255. Hex is compact, so it is common in style sheets, design tools, and brand guides. It is not easy to read by eye, because a pair such as 57 does not immediately tell you how much green it means.
RGB writes the same three channels in decimal, like rgb(255, 87, 51). The numbers are the same values as the hex pairs, just written in a form that is easier to understand. Red is 255, green is 87, and blue is 51 in the example above. RGB is useful when you need to see the amounts directly, or when you need to add an alpha value for transparency, such as rgba(255, 87, 51, 0.8). The alpha value is separate from the color itself, and it controls how see-through the color appears.
HSL describes color in a different way: hue, saturation, and lightness. Hue is the position on a color wheel, measured in degrees from 0 to 360. Saturation is how vivid the color is, from 0 percent gray to 100 percent full color. Lightness is how light or dark the color is, from 0 percent black to 100 percent white. HSL is written like hsl(11, 100%, 60%). It does not tell you the red, green, and blue amounts directly. It tells you the character of the color, which makes it easier to adjust.
How the Formats Relate
Hex and RGB are two spellings of the same idea. Both describe a color by how much red, green, and blue light it contains. Converting between hex and RGB is a change of number base, not a change of color. If the conversion is done correctly, the color stays exactly the same. That is why a converter is reliable for this step: it follows the same arithmetic every time, and it does not depend on how the color looks on your screen.
HSL is a different model of the same color. It is calculated from the red, green, and blue values. A correct conversion should also give the same color, but the numbers are often rounded. For example, a hue may be rounded to the nearest whole degree, and saturation and lightness may be rounded to whole percentages. Small rounding differences are usually not visible, but they can matter if you convert back and forth many times. Each round trip can drift a little, so it is best to keep the original value and convert from it each time, rather than converting a converted value again and again.
It helps to think of the formats as tools for different jobs. Use hex when you need a compact value for a style sheet or a brand guide. Use RGB when you need to see the channel amounts or add transparency. Use HSL when you need to make a lighter version, a darker version, or a more muted version of a color. Choosing the right format for the task makes the work easier and reduces the chance of a mistake.
How to Convert Step by Step
- Start with the exact source value. Copy the hex, RGB, or HSL value from the source. Do not retype it from memory if you can avoid it. A single wrong character changes the color.
- Use a converter. Paste the value into a color converter, such as a converter tool on a trusted site or in your design tool. Do not try to eyeball the result.
- Copy the result. Copy the converted value from the converter, not from a screenshot or a color swatch. Paste it where it will be used.
- Check the color side by side. Place the original and the converted color next to each other. They should look the same. If they do not, one of the values was copied wrong.
- Test in context. View the converted color on the real background, with real text, at the real size. A color that matches in a swatch can still look different next to other colors.
- Save the original. Keep a note of the original value and the converted value together. That makes it easy to check later without converting again.
- Check contrast. If the color will be used behind text, check that the text still has enough contrast. Conversion does not change contrast, but a later HSL adjustment can.
- Use HSL for adjustments. If you need a lighter or darker version, adjust lightness in HSL, then convert the result back if you need hex or RGB.
Worked Example: Converting #FF5733
Suppose you have the hex color #FF5733 and you need RGB and HSL. The worked example below shows the conversion in full, so you can follow each part. The result is #FF5733 = rgb(255, 87, 51) = hsl(11, 100%, 60%). These three values describe the same warm orange-red color. You can use any of them in CSS, depending on what the task needs.
First, split the hex into three pairs: FF, 57, and 33. The first pair is red, the second is green, and the third is blue. Next, convert each pair from base sixteen to decimal. FF becomes 255, because F stands for 15, and 15 times 16 plus 15 equals 255. The pair 57 becomes 87, because 5 times 16 plus 7 equals 87. The pair 33 becomes 51, because 3 times 16 plus 3 equals 51. That gives the RGB value rgb(255, 87, 51). A converter does this arithmetic for you, and it removes the chance of a small multiplication mistake.
Next, convert the RGB value to HSL. A converter calculates the hue, saturation, and lightness from the red, green, and blue amounts. For this color, the hue is 11 degrees, which sits in the orange-red part of the color wheel. The saturation is 100 percent, which means the color is fully vivid. The lightness is 60 percent, which means it is a little above the middle of the light-to-dark range. That gives the HSL value hsl(11, 100%, 60%). If you paste this HSL value into a style sheet, it should match the original hex color.
Now use HSL to make adjustments. If you want a lighter version, increase the lightness, for example from 60 percent to 70 percent, while keeping the hue and saturation the same. If you want a darker version, reduce the lightness to 50 percent or 45 percent. If you want a more muted version, reduce the saturation from 100 percent to 70 percent or 60 percent. Each change is easy to describe and easy to undo, because you only change one number at a time. That is the main advantage of HSL: it separates the character of the color from its brightness.
Do Not Eyeball Conversions
The most common mistake in color conversion is guessing. A person may look at a hex color, try to pick a similar color from a picker, and assume it is close enough. On some screens, two similar colors may look the same. On another screen, in print, or next to a different background, the difference can become visible. A brand color that is slightly off can also make a site look inconsistent, even if no one can name the exact difference.
Another mistake is converting from a converted value instead of from the original. For example, converting hex to HSL, then converting that rounded HSL back to hex, can give a slightly different hex value than the original. The difference is usually small, but it can grow if you repeat the process. Always keep the original value, and convert from it each time you need a new format. If you need to adjust the color, make the adjustment in HSL, save the new HSL value, and convert from that saved value.
It is also a mistake to trust a screenshot. A screenshot may be compressed, resized, or shown on a screen with different color settings. The hex or RGB value in the file is the reliable source. If you need to match a color from an image, use a color picker tool that reads the exact pixel value, rather than guessing from how the image looks on your screen.
Using HSL for Adjustments
HSL is especially useful when you need a family of colors. Start with one base color, then create lighter and darker versions by changing lightness only. For example, a base color at 60 percent lightness can have a light version at 75 percent, a dark version at 45 percent, and a very dark version at 30 percent. Because the hue and saturation stay the same, the colors will feel related. That is useful for buttons, hover states, backgrounds, and borders.
Saturation is useful when you need a muted version. A color at 100 percent saturation can feel loud, especially on a large background. Reducing saturation to 70 percent or 50 percent makes the same hue feel calmer, without changing the hue. That can be useful for backgrounds, cards, and large sections. For text, saturation matters less than contrast. A muted color behind text still needs enough contrast with the text color.
Hue is useful when you need a related color, such as a slightly warmer or cooler version. A small change in hue, such as from 11 degrees to 20 degrees, shifts the color toward orange. A larger change moves it toward yellow or red. Small hue changes are safer than large ones, because they keep the color in the same family. Large hue changes can make the new color feel unrelated to the original, even if the saturation and lightness stay the same.
Checking Your Work
After a conversion, check the result in three ways. First, compare the values. The converted value should come from a converter, not from memory. Second, compare the swatches side by side. The original and converted swatches should match. Third, test the color in context. Place it on the page, next to the other colors it will sit with, and view it on more than one device if you can. A color that matches in a tool can still look different in context if the surrounding colors change how it is perceived.
Also check the format your tool expects. Some tools expect hex without a hash, some expect RGB with commas, and some expect HSL with percentages. A value that is correct in one format can be rejected in another if the punctuation is wrong. Copy the full value, including the hash, parentheses, commas, and percent signs, and check that the result appears as expected after you paste it.
Limitations
Conversion cannot fix a poor color choice. If the original color has low contrast with the text, the converted color will have the same low contrast. If the original color does not fit the design, the converted color will not fit either. Conversion changes the spelling of a color, not its suitability. Always check contrast, readability, and the overall palette after conversion.
Conversion also has practical limits. Different tools may round HSL values differently, so the same RGB color can give slightly different HSL values in different converters. Color displays also vary, so the same value can look slightly different on different screens. Do not rely on a single screen to judge a color. Use the numeric values as the source of truth, and test on more than one device when the color is important.
Finally, conversion does not guarantee accessibility. A color that is converted correctly still needs enough contrast with the text or background it sits on. A color that looks good in a swatch may be hard to read when used for small text. Check contrast with a contrast checker, and do not use color alone to communicate an important meaning, such as an error or a required field. Pair color with text or an icon.
Frequently Asked Questions
What is the RGB and HSL value of #FF5733?
The RGB value is rgb(255, 87, 51), and the HSL value is hsl(11, 100%, 60%). The hex pairs FF, 57, and 33 convert to 255, 87, and 51. A converter gives the HSL value from those RGB amounts. Use a converter to check the result, rather than guessing.
Should I use hex, RGB, or HSL in CSS?
Use the format that fits the task. Hex is compact and common for brand colors. RGB is clear when you need the channel amounts or transparency. HSL is best when you need to adjust lightness or saturation. All three can describe the same color, so choose the one that makes the work easiest to check.
Why does my converted color look slightly different?
It is often caused by rounding, by converting from a converted value, or by a copying mistake. Convert from the original value, use a converter, and compare the swatches side by side. Check that you copied the full value, including punctuation, and test the color on the real background.
Can I use HSL to make a lighter version of a color?
Yes. Keep the hue and saturation the same, and increase the lightness. For example, change lightness from 60 percent to 70 percent for a lighter version, or to 50 percent for a darker version. Changing one number at a time makes the adjustment easy to describe and easy to undo.
Conclusion
Converting colors between hex, RGB, and HSL is straightforward when you use the exact source value and a converter. Hex and RGB describe the same red, green, and blue amounts in different number bases. HSL describes the same color by hue, saturation, and lightness, which makes it easier to adjust. The worked example #FF5733 = rgb(255, 87, 51) = hsl(11, 100%, 60%) shows how the three formats line up. Do not eyeball conversions, do not convert from a converted value, and always check the result in context. When you keep the original, convert with a tool, and use HSL for adjustments, your colors will stay consistent across the site.
Try a Tool
Free, in your browser — no sign-up.
Related Articles
How to Pick a Colour From an Image (Without Guessing)
Pick an exact colour from any image with an eyedropper, save the hex code, test contrast, and keep your palette small.
Read article →How to Find a Font From an Image (the Practical Way)
Identify a font from an image with a clean crop, compare candidates letter by letter, check licences, and test lookalikes.
Read article →How to Minify CSS Without Breaking Your Styles
Learn how to minify CSS without breaking your styles. Keep an unminified source, preserve required spaces, and test after minifying.
Read article →