RGB to HEX Converter
Quickly turn rgb(r, g, b) values into HEX color codes. This converter is helpful when you work with CSS, design tokens, or want to align colors across design tools and code.
Type a value in RGB or HEX format, and the second field updates right away. The conversion works both ways, so you can start from whichever format is more convenient for your workflow.
You can also experiment with the color picker. As you move the handle, the RGB and HEX values are recalculated instantly, which makes it easy to fine-tune accent colors, backgrounds, or semantic tokens.
Understanding RGB Colors
The RGB model describes a color as a mix of red, green, and blue light. Each component is a number from 0 to 255, where 0 means that channel is off and 255 means full intensity.
When these three channels are combined, they form the colors you see on monitors, phones, and televisions. For example, rgb(255, 255, 255) is white, rgb(0, 0, 0) is black, and rgb(255, 165, 0) corresponds to a bright orange tone.
RGB values are especially practical in dynamic interfaces, because you can manipulate each channel programmatically, generate color palettes, and create transitions that interpolate between numeric values.
What Is a HEX Color Code?
A HEX color is the same RGB color written in the hexadecimal system. The standard format is #RRGGBB, where each pair of characters represents the red, green, and blue channel in base 16.
Instead of decimal numbers from 0 to 255, HEX uses values from 00 to FF. The digits A–F stand for the decimal numbers 10 to 15. Browsers parse the string, split it into three pairs, convert each one to decimal, and then render the corresponding RGB color.
This compact format is widely used in CSS, design tools, and style guides because it is short, easy to copy, and works well as a token for primary, secondary, and semantic colors.
RGB to HEX Conversion Formula
rgb(r, g, b) → #RRGGBB
RR = dec_to_hex(r)
GG = dec_to_hex(g)
BB = dec_to_hex(b)
// Helper:
dec_to_hex(x) = to_hex(x).padStart(2, "0")To convert from RGB to HEX, you transform each channel value (from 0 to 255) into a two-digit hexadecimal string and then concatenate the three parts with a leading #.
// Example for rgb(79, 163, 194)
r = 79 → 4F
g = 163 → A3
b = 194 → C2
#4FA3C2If you want to review how hexadecimal numbers work or how base conversion is performed, you can open the <a href="/number-systems" rel="noopener noreferrer">number system guide</a>.
How RGB to HEX Conversion Works Step by Step
RGB values are written as three decimal numbers. During conversion, each of these numbers is translated into a two-digit HEX fragment and then combined into a single color code.
rgb(26, 43, 60)
↓ ↓ ↓
[26, 43, 60] → #1A2B3CHere is a detailed breakdown for rgb(26, 43, 60):
- Step 1 — Separate the three channels:
[26] [43] [60] - Step 2 — Convert each value from decimal to HEX:
You repeatedly divide the decimal value by 16 or use a built-in helper function. The remainder at each step is mapped to a HEX digit (0–9, A–F).
26 → 1A 43 → 2B 60 → 3CIn this example, all three channels stay within 0–255, so each one becomes a two-character HEX fragment.
- Step 3 — Join the parts and prepend the # symbol:
#1A2B3C
The same approach works for any valid RGB triplet: convert each component independently, then join the results into a single HEX code.
Choosing Between RGB and HEX in CSS
Both RGB and HEX describe the same colors, but one format can be more convenient than the other depending on the situation. The choice usually comes down to how you read, edit, and share color values in a project.
When RGB Is More Practical
- Explicit channel control: the values for red, green, and blue are visible right in the function call, which is useful for animations or algorithmic color generation.
- Fine-tuning with JavaScript: numeric channels are easy to increase, decrease, or clamp in code.
- Working with transparency: the
rgba()variant adds an alpha parameter while keeping the same structure, which is handy for overlays and shadows.
When HEX Is a Better Fit
- Compact notation: a short string like
#1A2B3Cis comfortable for tokens, design systems, and shared palettes. - Alignment with design tools: most graphic editors display and export colors in HEX by default, so you can copy values without any additional conversion.
- Readable presets: HEX codes are easy to scan when you maintain a list of primary, secondary, and neutral colors for the interface.
Summary
Use RGB/RGBA when you need to manipulate color channels or opacity directly in code. Prefer HEX when you want a concise, stable value for a design token or when you primarily copy colors from design tools. You can always convert between them without losing precision.
Practical Tips for Handling Colors in CSS
Modern CSS accepts multiple color formats, so it is worth choosing one or two as a standard inside your project. This keeps design tokens consistent and makes styles easier to maintain.
Pick a Primary Color Format
- HEX: good as a base format for design systems and documentation.
- RGB/RGBA: convenient for effects, overlays, and state transitions where opacity matters.
- HSL/HSLA: helpful when you want to adjust hue, saturation, or lightness in a predictable way.
Use Shorthand Carefully
- #RGB instead of #RRGGBB: the three-character form is valid only when each pair consists of identical digits. For example,
#FA3expands to#FFAA33.
Writing HEX With Alpha
- #RRGGBBAA: this is the eight-character HEX format that includes opacity. The last two digits define the alpha channel from
00(transparent) toFF(fully opaque). - If you already use HEX tokens, HEX with alpha lets you keep the same style while adding transparency where needed.
Typical Pitfalls
- Mixing many formats in one file: sticking to a small set of formats keeps themes and refactors simpler.
- Animating HEX directly: for smoother transitions, switch to
rgb(),rgba(), orhsl()in keyframes. - Forgetting about contrast: when defining colors, always check readability on both light and dark backgrounds.
With a consistent approach to color formats and a clear token strategy, styles stay readable, scalable, and easier to refactor as the design evolves.
RGB to HEX Conversion Table
The following reference table shows several common colors in both RGB and HEX forms. You can use it as a quick lookup while working with themes, layouts, or brand palettes.
| Description | HEX | RGB |
|---|---|---|
| White | #FFFFFF | rgb(255, 255, 255) |
| Black | #000000 | rgb(0, 0, 0) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Green | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Yellow | #FFFF00 | rgb(255, 255, 0) |
| Cyan | #00FFFF | rgb(0, 255, 255) |
| Magenta | #FF00FF | rgb(255, 0, 255) |
| Gray 1 | #111111 | rgb(17, 17, 17) |
| Gray 2 | #333333 | rgb(51, 51, 51) |
| Gray 3 | #555555 | rgb(85, 85, 85) |
| Gray 4 | #777777 | rgb(119, 119, 119) |
| Gray 5 | #999999 | rgb(153, 153, 153) |
| Gray 6 | #CCCCCC | rgb(204, 204, 204) |
| Light gray | #F0F0F0 | rgb(240, 240, 240) |
| UI gray | #E0E0E0 | rgb(224, 224, 224) |
| Dark UI gray | #1A1A1A | rgb(26, 26, 26) |
| Dark red | #800000 | rgb(128, 0, 0) |
| Dark green | #008000 | rgb(0, 128, 0) |
| Dark blue | #000080 | rgb(0, 0, 128) |
| Orange | #FFA500 | rgb(255, 165, 0) |
| Purple | #800080 | rgb(128, 0, 128) |
| Teal | #008080 | rgb(0, 128, 128) |
For any other RGB combination, you can use the converter at the top of the page to obtain the exact HEX code.
FAQ: RGB to HEX
- Why do RGB values always fall between 0 and 255?
Each RGB channel is stored as an 8-bit value. Eight bits can represent 256 distinct states, which correspond to the range from
0to255. - What happens if a value is outside this range?
Values lower than
0are treated as0, and values above255are clamped to255. For consistent results, validate your RGB input before converting it to HEX. - Does RGB to HEX conversion change the actual color?
No. RGB and HEX are just two representations of the same color data. As long as each channel stays within 0–255, the conversion is lossless.
- Is there a shorthand form for some RGB values in HEX?
Yes. If each pair of HEX digits is made up of the same character, you can compress
#RRGGBBinto#RGB. For instance,#FF00AAbecomes#F0A. - How do I represent transparency when converting from RGB?
You can either keep using
rgba()in CSS or switch to the extended HEX format#RRGGBBAA, where the last two digits represent the alpha channel.
Related Converters:
HEX to RGB Converter
Instantly calculate hex to rgbHEX to HSL Converter
Instantly calculate hex to hslHEX to HSV Converter
Instantly calculate hex to hsvRGB to HSL Converter
Instantly calculate rgb to hslRGB to HSV Converter
Instantly calculate rgb to hsvHSL to HEX Converter
Instantly calculate hsl to hex