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.
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:
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)\).
Worked Example
Take the hex code #3498DB. Splitting it gives the pairs 34, 98, and DB. Converting each:
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.