How to Convert HEX to RGB Color Codes: Step-by-Step Examples
Updated: November 6, 2026 · AracMerkezi
A HEX color code writes the 0–255 values of the red, green and blue channels side by side in hexadecimal: #RRGGBB and rgb(R, G, B) are two notations for the same color, and each channel is converted with the rule "first character × 16 + second character". This guide shows the conversion step by step with three examples, explains short HEX and 8-digit (transparency) HEX, gives verified commands you can use on the coding side, and works out how to darken and lighten a color. We verified the conversions in the examples by running them in JavaScript and Python.
Hexadecimal in brief
The hexadecimal system uses the digits 0–9 and the letters A–F: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15. A two-digit number is read as first digit × 16 + second digit; the smallest is 00 = 0 and the largest is FF = 15 × 16 + 15 = 255. So a channel takes 256 different values and the three channels together give 256³ = 16,777,216 colors.
Converting HEX to RGB
Split the #RRGGBB code into three two-character groups and convert each group to decimal.
Example 1: #0B7A6B
- 0B = 0 × 16 + 11 = 11
- 7A = 7 × 16 + 10 = 122
- 6B = 6 × 16 + 11 = 107
- Result: rgb(11, 122, 107)
Example 2: #FF8800 → FF = 15 × 16 + 15 = 255; 88 = 8 × 16 + 8 = 136; 00 = 0 → rgb(255, 136, 0) (orange).
Converting RGB to HEX
Divide each number by 16; the quotient gives the first digit and the remainder the second.
Example 3: rgb(26, 43, 60)
- 26 = 1 × 16 + 10 → 1A
- 43 = 2 × 16 + 11 → 2B
- 60 = 3 × 16 + 12 → 3C
- Result: #1A2B3C
Table of common colors
| HEX | RGB | Color |
|---|---|---|
| #FF0000 | rgb(255, 0, 0) | red |
| #00FF00 | rgb(0, 255, 0) | green |
| #0000FF | rgb(0, 0, 255) | blue |
| #FFFF00 | rgb(255, 255, 0) | yellow |
| #FFA500 | rgb(255, 165, 0) | orange |
| #800080 | rgb(128, 0, 128) | purple |
| #808080 | rgb(128, 128, 128) | gray |
| #FFFFFF | rgb(255, 255, 255) | white |
In gray tones the three channels are equal: #808080 = rgb(128, 128, 128). The gray line from black to white consists of the values where R = G = B.
Short HEX and 8-digit HEX
- Short notation: If both characters are the same in every channel, it can be written with three digits: #FA0 instead of #FFAA00. The short code expands by doubling each character: #FA0 → #FFAA00 → rgb(255, 170, 0).
- 8-digit HEX (transparency): The last two digits are the alpha channel. For #0B7A6B80, 80 = 8 × 16 = 128 and 128 / 255 = 0.502; that is about 50% opacity, equivalent to
rgba(11, 122, 107, 0.5)in CSS. The tool converts only between RGB and HEX; do this calculation by hand for transparency.
Example 4: Darkening and lightening a color
Let #0B7A6B be your main color, rgb(11, 122, 107).
- 20% darker: Multiply each channel by 0.8: 11 × 0.8 = 8.8 → 9; 122 × 0.8 = 97.6 → 98; 107 × 0.8 = 85.6 → 86. rgb(9, 98, 86) → #096256.
- 30% lighter (toward white): v + (255 − v) × 0.3: 11 → 84; 122 → 162; 107 → 151. → #54A297.
This is a simple approximation compared with HSL, which handles saturation and lightness separately on the color wheel; but it is enough for quickly deriving hover and border shades of a brand color.
Example 5: Reading the channels as percentages
Some tools ask for the channels as 0–100 percentages. For rgb(11, 122, 107): 11 / 255 = 4.3%, 122 / 255 = 47.8%, 107 / 255 = 42.0%. In CSS this can be written as rgb(4.3% 47.8% 42%). That green and blue are high and red is low also explains why #0B7A6B is a dark teal green: the dominant channels set the hue of the color, and their total size sets its brightness.
Where do color codes show up?
The same code circulates in CSS files, design tools, email templates and brand guides. A designer hands over HEX, a charting library wants an RGB array, a mobile app constant expects floating-point values in the 0–1 range. They are all the same three numbers; only the notation changes. Keeping your brand color in a single source (for example a variables file) and deriving the other formats by calculation prevents color drift across platforms.
Conversions verified in code
- JavaScript:
parseInt('7A', 16)→ 122;(122).toString(16)→7a; for two digits add.padStart(2, '0'):(9).toString(16).padStart(2, '0')→09. - Python:
int('7A', 16)→ 122;f'{122:02X}'→7A;f'#{11:02X}{122:02X}{107:02X}'→#0B7A6B. - In CSS the two are equivalent:
color: #0B7A6B;andcolor: rgb(11, 122, 107);.
Common mistakes
- Forgetting to pad single-digit results with a zero: 9 →
09, not9. Otherwise a broken code like #96256 results. - Mixing up the letter O with the digit 0.
- Writing an RGB value above 255.
- Expanding short HEX wrongly: #FA0 is #FFAA00, not #FA0000.
- Treating the alpha value in 8-digit HEX as 0–100 and reading it directly as a percentage; it is 0–255.
- Not checking the text color against the background; white text on light gray is unreadable.
Accessibility
It is not enough for a color to look good; there must be enough contrast between text and background. For details see What Is Color Contrast Ratio? WCAG AA and AAA, and for choosing a palette see How to Choose a Color Palette for a Website.
The HEX ↔ RGB Converter accepts formats such as #1A2B3C or 26,43,60. For HSL and CMYK you can use the Color Code Converter, and for contrast the Color Contrast Checker. The JSON Formatter and UUID Generator tools are also available for developers.
Frequently asked questions
Which RGB value does #0B7A6B correspond to?
Since 0B = 11, 7A = 122 and 6B = 107, #0B7A6B equals rgb(11, 122, 107).
How does short HEX notation work?
If both characters of every channel are the same, each character is doubled: #FA0 means #FFAA00 (rgb(255, 170, 0)).
What range do RGB values have?
Each channel is between 0 and 255, which corresponds to 00 through FF in hexadecimal. The three channels together give 16,777,216 colors.
Tools mentioned in this guide
More guides
- How to Choose a Color Palette for a Website: Building a Full Palette From One Color – How to choose a website color palette: build tints, accents and neutrals from one HEX color, with the 60-30-10 rule, contrast values and CSS variables.
- How to Create a Secure Password: Length, Entropy and 8 Rules – How to create a secure password: password strength in bits, random-word passphrases, command-line generation and eight practical rules.
- What Is Color Contrast Ratio? A Step-by-Step WCAG AA and AAA Calculation with Example Colors – How is color contrast ratio calculated? WCAG AA and AAA thresholds (4.5:1, 3:1, 7:1), the luminance formula, worked color examples and tips.
- What Is Base32? Base32 vs Base64, Step-by-Step Encoding and TOTP Keys – How does Base32 work? Encode 'foo' to MZXW6=== bit by bit, compare sizes with Base64 and hex, and see why two-factor secrets are shown in Base32.
- Binary, Decimal and Hexadecimal Number Systems: Methods for Converting Between Bases – How do you convert between binary, octal, decimal and hexadecimal? The division and grouping methods, bit limits and worked examples.
This article is for general information only and is not legal, financial or medical advice. We are not an official institution.