RGB to Hex Converter
The RGB to Hex Converter takes the red, green, and blue values you enter in RGB Input (R, G, B) and combines them into a hex color code. Click Convert and your six-digit code appears in Hex Output, ready to paste straight into your CSS. The binary to text converter reads each value in your binary input as a character code point and turns it back into readable text instantly.
Visual Guide: rgb to hex Color Comparison Table
How the rgb to hex Conversion Works
The rgb to hex method translates an RGB shade, input as values for red, green, and blue components ranging from 0 to 255, into a 6-digit hex color code (#RRGGBB). Each part (r, g, b) is individually turned into a two-digit hex number, then concatenated in order. The formula for this conversion is: Use the hex to cmyk converter to check how an on-screen hex color will translate into CMYK ink percentages before sending a file to print.
- Formula:
- Convert each channel:
$$R_{hex} = \text{toHex}(R)$$
$$G_{hex} = \text{toHex}(G)$$
$$B_{hex} = \text{toHex}(B)$$
Concatenate as:#RRGGBB
The function toHex(x) converts the numeric amount x to a two-digit hexadecimal string, padding with a leading zero if necessary. The hex to hsl converter calculates the hue, saturation, and lightness values behind any hex color, formatted for CSS.
For example, rgb(57,77,254) translates as:
- Red: 57 (
39in hex) - Green: 77 (
4Din hex) - Blue: 254 (
FEin hex)
Hex result: #394DFE
This process lets you convert any rgb value and get the corresponding 6-digit hex for use in markup, stylesheets, web authoring, and graphic layouts.
Sample rgb to hex Conversions and Color Codes Table
Below is a quick reference rgb to hex color table showing some common shade notations with their rgb, hex, and a live color swatch for easy comparison. Use this chart to explore some hues and see how rgb maps directly to hex strings like #ff0000 or #394dfe. To explore individual values for red code, green code, and blue code, enter a color code below to see the conversion.
| Color Name | (R,G,B) | Hex Code | Color Swatch |
|---|---|---|---|
| Black | (0, 0, 0) | #000000 | |
| White | (255, 255, 255) | #ffffff | |
| Red | (255, 0, 0) | #ff0000 | |
| Lime | (0, 255, 0) | #00ff00 | |
| Blue | (0, 0, 255) | #0000ff | |
| Yellow | (255, 255, 0) | #ffff00 | |
| Cyan | (0, 255, 255) | #00ffff | |
| Magenta | (255, 0, 255) | #ff00ff | |
| Silver | (192, 192, 192) | #c0c0c0 | |
| Gray | (128, 128, 128) | #808080 | |
| Maroon | (128, 0, 0) | #800000 | |
| Olive | (128, 128, 0) | #808000 | |
| Green | (0, 128, 0) | #008000 | |
| Purple | (128, 0, 128) | #800080 | |
| Teal | (0, 128, 128) | #008080 | |
| Navy | (0, 0, 128) | #000080 |
This comparison demonstrates the identical appearance in both the rgb (numeric) and hex (hexadecimal) notation. Adjust the bands to convert each component to hex and achieve the desired shade for your web design or markup.
Worked Examples: Convert RGB to Hexadecimal Code
- Convert pure red color (255, 0, 0) to hex color code
- Known values: R = 255, G = 0, B = 0
- Apply formula:
#RRGGBB - Convert each part:
R: 255 →FFhex
G: 0 →00hex
B: 0 →00hex - Result:
#ff0000
- Convert a web-safe blue shade (0, 85, 255) to hex
- Known values: R = 0, G = 85, B = 255
- Apply formula:
#RRGGBB - Convert each part:
R: 0 →00hex
G: 85 →55hex
B: 255 →ffhex - Result:
#0055ff
- Convert a gray tone (128, 128, 128) to hex
- Known values: R = 128, G = 128, B = 128
- Apply formula:
#RRGGBB - Convert each part:
R: 128 →80hex
G: 128 →80hex
B: 128 →80hex - Result:
#808080
These examples show how to convert the red, green and blue channel code values from numbers to hex for any given color. Remember, the outputs are always in full six-digit hex for universal compatibility. Try to enter a color code and see how its red code, green code, and blue code convert to a single hex.

RGB vs. Hex: Choosing the Right Color Format for CSS
Both rgb() and six-digit hex color codes describe the exact same 24-bit color space in CSS — rgb(255, 102, 0) and #FF6600 render identically in every modern browser — so the choice usually comes down to where the value came from and how it's going to be used next.
- Use rgb values when you're reading color straight out of a design tool's color picker, an image-editing app's eyedropper, or a canvas/pixel API that already reports red, green, and blue as separate 0–255 numbers.
- Use hex codes once that color is heading into a stylesheet, a design token, an SVG
fillattribute, or anywhere brevity matters — a hex string is shorter to type and easier to scan in a long CSS file than three comma-separated numbers. - Convert between the two whenever a handoff crosses that boundary — a designer hands off RGB swatches from Figma or Photoshop, and the resulting hex codes are what actually get committed to the codebase.
This rgb to hex converter exists for exactly that handoff moment: paste the R, G, B values you were given, and get back the six-digit hex code ready to paste into color:, background-color:, or any other CSS property that expects a hex color.
How to Use the RGB to Hex Converter
This converter is processed locally—meaning your chromatics you paste never leave your browser. Whether you're working with rgb(57,77,254) for a curious blue or #808080 for gray, you can copy the hex and use that shade instantly across platforms. If you're working with images, visual software, or front-end development, the rgb to hex converter keeps your tints unified, minimizing manual math and maximizing accuracy. Try to enter a color code, and let this tool convert rgb to hex without error.