Connect via MCP →

Enter Calculation

Enter a 3 or 6 digit hex code, with or without #

Formula

Advertisement

Results

RGB Color
rgb(52, 152, 219)
Red (R) 52
Green (G) 152
Blue (B) 219

What Is a Hex to RGB Converter?

A hex color code is a six-digit hexadecimal representation of a color used widely in web design, CSS, and graphics software. A Hex to RGB converter translates that code into its three component channels — Red, Green, and Blue — each expressed as a decimal number between 0 and 255. RGB values are useful in many programming languages, design tools, and contexts where hexadecimal isn't accepted.

Three overlapping circles in red, green, and blue showing additive color mixing
RGB describes color as a mix of red, green, and blue light.

How to Use It

Type a hex code into the box. You can include the leading # or omit it, and you may use the full six-digit form (e.g. #3498db) or the three-digit shorthand (e.g. #f00), which is automatically expanded. Press calculate to see the equivalent RGB values and a live color swatch.

The Formula Explained

A hex code is split into three two-character pairs. Each pair is a base-16 number that is converted to base-10 (decimal). For example, the pair FF equals \(15 \times 16 + 15 = 255\), the maximum value for a channel, while 00 equals 0, the minimum. The general rule is:

$$(R,\,G,\,B) = \bigl(\text{hex}_{1\text{-}2},\ \text{hex}_{3\text{-}4},\ \text{hex}_{5\text{-}6}\bigr)_{16}$$

that is, \(R = \text{int}(\text{hex}[0{:}2],\ 16)\), \(G = \text{int}(\text{hex}[2{:}4],\ 16)\), and \(B = \text{int}(\text{hex}[4{:}6],\ 16)\).

Diagram showing a six-digit hex code split into three color-coded pairs mapping to red, green and blue values
A hex code splits into three pairs that become the red, green, and blue values.

Worked Example

Take the hex code #3498DB. Splitting it gives the pairs 34, 98, and DB. Converting each:

$$\begin{aligned} \texttt{34} &= 3 \times 16 + 4 = 52 \\ \texttt{98} &= 9 \times 16 + 8 = 152 \\ \texttt{DB} &= 13 \times 16 + 11 = 219 \end{aligned}$$

The result is \(\text{rgb}(52,\ 152,\ 219)\), a pleasant sky blue.

FAQ

Do I need the # symbol? No. The converter ignores the hash and any non-hex characters, so both #fff and fff work.

What about 3-digit hex codes? Shorthand codes like #abc are expanded to #aabbcc automatically before conversion.

What is the maximum RGB value? Each channel ranges from 0 (hex 00) to 255 (hex FF), giving \(16{,}777{,}216\) possible colors.

Last updated: