RGB to Hex Color Converter
Convert RGB color values to Hex codes and Hex to RGB instantly. Live preview, color picker, sliders, presets, and copy-to-clipboard support.
About
Color format mismatches between design tools and code cause silent rendering errors. Photoshop exports R, G, B triplets in the range 0 - 255, while CSS shorthand expects a 6-digit hexadecimal string prefixed with #. A single transposed digit produces a wrong hue with no compiler warning. This converter performs bidirectional translation between the two notations and displays a live swatch so you can visually verify the result before pasting it into your stylesheet or design token file.
The tool also computes relative luminance using the ITU-R BT.601 luma formula (Y = 0.299R + 0.587G + 0.114B) to recommend a contrasting text color. Note: this approximation applies to sRGB gamma-encoded values and does not account for wide-gamut displays.
Formulas
Each RGB channel is an integer in the range [0, 255]. The hexadecimal representation converts each channel independently to a base-16 string of exactly two characters:
where pad left-pads with a zero if the result is a single digit. The reverse operation parses each two-character substring back to decimal:
G = parseInt(hex[3..4], 16)
B = parseInt(hex[5..6], 16)
Relative luminance for contrast detection uses the ITU-R BT.601 luma coefficient weighting:
Where R, G, B ∈ [0, 255] are the red, green, and blue channel values. Y > 128 indicates a light color (use dark text). pad denotes zero-padding to two characters. parseInt converts a hexadecimal substring to its decimal integer equivalent.
Reference Data
| Color Name | Hex Code | R | G | B | CSS Keyword | Category |
|---|---|---|---|---|---|---|
| White | #FFFFFF | 255 | 255 | 255 | white | Neutral |
| Black | #000000 | 0 | 0 | 0 | black | Neutral |
| Red | #FF0000 | 255 | 0 | 0 | red | Primary |
| Lime | #00FF00 | 0 | 255 | 0 | lime | Primary |
| Blue | #0000FF | 0 | 0 | 255 | blue | Primary |
| Yellow | #FFFF00 | 255 | 255 | 0 | yellow | Secondary |
| Cyan | #00FFFF | 0 | 255 | 255 | cyan | Secondary |
| Magenta | #FF00FF | 255 | 0 | 255 | magenta | Secondary |
| Coral | #FF7F50 | 255 | 127 | 80 | coral | Warm |
| Tomato | #FF6347 | 255 | 99 | 71 | tomato | Warm |
| Orange | #FFA500 | 255 | 165 | 0 | orange | Warm |
| Gold | #FFD700 | 255 | 215 | 0 | gold | Warm |
| Violet | #EE82EE | 238 | 130 | 238 | violet | Cool |
| Indigo | #4B0082 | 75 | 0 | 130 | indigo | Cool |
| Teal | #008080 | 0 | 128 | 128 | teal | Cool |
| Steel Blue | #4682B4 | 70 | 130 | 180 | steelblue | Cool |
| Slate Gray | #708090 | 112 | 128 | 144 | slategray | Neutral |
| Peru | #CD853F | 205 | 133 | 63 | peru | Earth |
| Sienna | #A0522D | 160 | 82 | 45 | sienna | Earth |
| Medium Spring Green | #00FA9A | 0 | 250 | 154 | mediumspringgreen | Green |
| Dodger Blue | #1E90FF | 30 | 144 | 255 | dodgerblue | Cool |
| Hot Pink | #FF69B4 | 255 | 105 | 180 | hotpink | Warm |
| Dark Olive Green | #556B2F | 85 | 107 | 47 | darkolivegreen | Earth |
| Rebecca Purple | #663399 | 102 | 51 | 153 | rebeccapurple | Cool |
| Light Salmon | #FFA07A | 255 | 160 | 122 | lightsalmon | Warm |