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 #FF0000
  • RGB(0, 128, 0) becomes #008000
  • RGB(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 255
  • G — Green channel intensity as a decimal number from 0 to 255
  • B — 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:

  1. Take your three decimal values. For example, if your colour is RGB(230, 126, 34), you have R=230, G=126, B=34.
  2. 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.
  3. 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.

Frequently Asked Questions

What's the difference between RGB and HEX colour notation?

RGB and HEX are two ways of representing the same colour data. RGB expresses colour as three separate decimal numbers (0–255) for red, green, and blue intensity. HEX converts those same three values into hexadecimal and combines them into a single six-character string prefixed with #. RGB is intuitive for displays and human understanding; HEX is more compact and is the standard format for web development, CSS, and HTML attributes. They are mathematically equivalent — one is simply a different number base representation of the other.

Can I convert HEX to RGB and back without losing colour information?

Yes, absolutely. RGB to HEX and HEX to RGB conversions are lossless and reversible. Every RGB value produces exactly one HEX code, and every valid HEX code corresponds to exactly one RGB triple. There is no degradation or approximation involved. For instance, <code>#A4D65E</code> converts precisely to <code>RGB(164, 214, 94)</code> every time. This one-to-one correspondence means you can confidently switch between formats without any risk of colour distortion.

What does RGB(0, 128, 0) look like, and what is its HEX equivalent?

<code>RGB(0, 128, 0)</code> represents a dark, forest green because only the green channel is lit at exactly half intensity (128 out of 255). The red and blue channels are completely off. Converting this: 0 in hex is 00, 128 is 80, and 0 is 00, giving you <code>#008000</code>. This colour is commonly used in web design as a standard 'success' or 'go' indicator because it sits comfortably between pure bright green and a muddy, desaturated tone.

How do I create gray using RGB values?

Gray in RGB requires equal intensity across all three channels. Any value N where N is the same for red, green, and blue produces a shade of gray. <code>RGB(128, 128, 128)</code> is mid-gray (#808080), <code>RGB(200, 200, 200)</code> is light gray (#C8C8C8), and <code>RGB(50, 50, 50)</code> is dark gray (#323232). The special case RGB(0, 0, 0) is pure black, and RGB(255, 255, 255) is pure white. Grays are neutral and free of colour cast, making them essential for UI backgrounds, text containers, and accessibility-compliant designs.

Why do designers use HEX instead of RGB in web development?

HEX is the standard in CSS because it is more compact and directly compatible with web standards and design tools. A single six-character string takes up less space than writing three separate decimal values, and most browsers, code editors, and design applications natively recognize and validate HEX notation. Additionally, HEX values copy and paste cleanly, version control tools handle them better, and team members can quickly spot and compare colour codes in code reviews. While both formats are mathematically identical, HEX has become the de facto convention in front-end development.

More conversion calculators (see all)