A design handoff says rgb(28, 94, 168), but your website editor asks for a HEX code. For an opaque sRGB color with integer channels from 0 to 255, you can change the notation without changing those channel values. The matching code here is #1c5ea8.
This guide covers that specific conversion. Decimal channels, transparency and wider color spaces need additional care; a similar-looking swatch alone does not prove that every value survived.
Check what the original value contains
Before converting, keep a copy of the original color. Identify its red, green and blue components, and look for an alpha value that controls transparency. MDN’s RGB reference explains that CSS rgb() describes sRGB colors and supports an optional alpha component.
rgb(28, 94, 168)has three integer channels and is fully opaque.rgba(28, 94, 168, 0.5)includes an alpha value of 0.5.- A value beginning with
color(display-p3 ...)is outside this guide’s ordinary RGB-to-HEX workflow. Do not treat its numbers as interchangeable with sRGB channels.
Convert the opaque RGB value
- Open the Color Converter and replace the current input with
rgb(28, 94, 168). - Read the updated HEX row. For this example, it should show
#1c5ea8. Results update as you enter the value. - Check the RGB row still contains 28, 94 and 168 in that order.
- Use the Copy button beside the HEX row and paste the value into your editor’s color field.
- For a reverse check, enter
#1c5ea8in the converter and confirm that the RGB channels return to the original three numbers.
Avoid selecting a tint or shade during this process: those controls intentionally change the color. If an invalid entry produces a warning, correct it before copying anything. The previous result can remain visible after an invalid input.
Understand the three HEX pairs
In six-digit HEX notation, the pairs represent red, green and blue, in that order. The CSS Color specification defines each pair as a hexadecimal value from 00 to ff. For our example, the conversion is:
| Channel | Decimal | HEX pair |
|---|---|---|
| Red | 28 | 1c |
| Green | 94 | 5e |
| Blue | 168 | a8 |
Join those pairs after the hash sign: #1c5ea8. For example, 1c means one group of sixteen plus twelve, giving 28. Capitalization does not alter the value, so #1C5EA8 is equivalent.
Three-digit shorthand works by repeating each digit. Thus #3a7 expands to #33aa77, which gives RGB channels 51, 170 and 119. You cannot shorten #1c5ea8 this way because its pairs do not contain repeated digits. See MDN’s HEX syntax reference for the supported forms.
Preserve alpha and avoid a rounded detour
Transparency needs its own check
For rgba(28, 94, 168, 0.5), the converter’s HEX output is #1c5ea880. The final pair is alpha. However, 80 represents 128 out of 255, approximately 0.502, rather than exactly 0.5. Keep the original RGBA value if that exact alpha matters. The converter’s plain RGB row omits transparency; use its RGBA row when you need alpha.
Keep the direct RGB-to-HEX route
The HSL row for this example rounds its values to whole numbers. Copying that rounded HSL value and converting it again can change the channels. Likewise, decimal RGB inputs may be rounded by the tool. Keep the original data when precision matters; the exact conversion demonstrated here starts with integer RGB channels.
Check the color in the finished component
These two CSS declarations describe the same opaque sRGB color:
.panel-hex { background-color: #1c5ea8; }
.panel-rgb { background-color: rgb(28 94 168); }
Inspect the actual component after saving. If its appearance differs, check whether another style overrides the declaration or whether opacity, a background image or a filter affects the result. Matching channel values does not guarantee identical appearance on every display.
Finally, evaluate text against the actual background. Converting notation does not improve readability. Our guide to choosing readable button text colors covers that separate check.