Understanding the RGB Color Model
RGB (Red, Green, Blue) is the additive color model that powers digital displays. Every pixel on your monitor, phone, or tablet relies on three light sources — red, green, and blue — blended in varying intensities to reproduce the full visible spectrum.
Each channel in RGB accepts a decimal value from 0 to 255, representing brightness:
- 0 means that colour is completely off (no light)
- 255 means that colour is at maximum intensity
- Any number in between represents a proportional brightness level
For example, RGB(255, 0, 0) produces pure red because only the red channel is at full strength. RGB(0, 255, 0) is pure green, and RGB(0, 0, 255) is pure blue. Combining all three at maximum (RGB(255, 255, 255)) yields white; setting all to zero (RGB(0, 0, 0)) produces black. By adjusting the three values independently, you can create over 16 million distinct colours.
The Hexadecimal Color Format Explained
Hexadecimal (HEX) notation is simply RGB data repackaged for programmers and web standards. Instead of writing three separate decimal numbers, HEX combines them into a compact six-character string prefixed with a hash symbol.
The conversion process is straightforward: each RGB decimal value is individually converted to a two-digit hexadecimal number, then concatenated together:
RGB(255, 0, 0)becomes#FF0000RGB(0, 128, 0)becomes#008000RGB(192, 192, 192)becomes#C0C0C0
HEX uses the digits 0–9 and letters A–F (where A=10, B=11, C=12, D=13, E=14, F=15). The advantage of HEX notation is that CSS stylesheets, HTML colour attributes, and design software all accept it directly, making it the lingua franca of web-based colour specification.
RGB to HEX Conversion Formula
Converting from RGB to HEX involves transforming each decimal value independently into a two-digit hexadecimal equivalent. The process follows this structure:
HEX = #(R in hex)(G in hex)(B in hex)
where each decimal value (0–255) converts to two hexadecimal digits (00–FF)
R— Red channel intensity as a decimal number from 0 to 255G— Green channel intensity as a decimal number from 0 to 255B— Blue channel intensity as a decimal number from 0 to 255
Step-by-Step Conversion Process
Converting RGB to HEX manually requires three simple steps:
- Take your three decimal values. For example, if your colour is
RGB(230, 126, 34), you have R=230, G=126, B=34. - Convert each decimal to hexadecimal. Use long division or a reference table: 230 in decimal is E6 in hexadecimal, 126 is 7E, and 34 is 22.
- Combine with a hash prefix. Concatenate the three two-digit hex values:
#E67E22. Leading zeros are always required; for instance,RGB(15, 0, 200)becomes#0F00C8, not#F00C8.
This format is what you paste into CSS colour properties, HTML colour attributes, and design applications. Learning this conversion reinforces understanding of number systems and prepares you for deeper work in web development.
Common Pitfalls When Converting RGB to HEX
Avoid these frequent mistakes during manual conversion or verification.
- Forgetting leading zeros — Hexadecimal numbers must always use two digits per channel. If a decimal value like 5 converts to the hex digit 5, you must write it as 05, not just 5. Omitting the leading zero results in a malformed colour code that browsers and software may not recognise correctly.
- Mixing uppercase and lowercase inconsistently — Hexadecimal allows both uppercase (FF) and lowercase (ff) letters, and most systems accept either. However, maintaining consistency throughout your stylesheets and documentation improves readability and prevents confusion when comparing colour values across files and team members.
- Confusing decimal-to-hex conversion boundaries — The decimal value 255 converts to FF in hexadecimal, not 100. Values from 0–9 stay the same in hex, but 10 becomes A, 15 becomes F, and 16 becomes 10. Mistakes here are easy to make; always double-check critical colours used in branding or accessibility requirements.
- Ignoring the hash prefix in CSS or HTML — Browsers require the # symbol at the start of a HEX colour code in CSS and HTML attributes. Writing E67E22 without the hash will be ignored or misinterpreted. Always include it as part of your colour specification.