What is RGB and How to Convert Hex into RGB?

Web Design | 13-01-2022 | Branson Tachao

what is rgb and how to convert hex into rgb

Since the most punctual long stretches of web improvement, there have been ways of determining colors in foundations, boundaries, text styles, and different components. Certain individuals utilize upheld shading catchphrases, while others utilize a more explicit shading framework like HSL (tint, immersion, daintiness).

In any case, today we will discuss the two most famous shading naming shows, RGB shading codes and hexadecimal (hex) shading codes.

RGB Color Codes

RGB shading codes, some of the time alluded to as RGBA shading codes when they incorporate an extra incentive for an alpha channel, are quite possibly the most famous way to characterize colors in pages.

Changing Hex Over to RGB

We will utilize the accompanying way to deal with converting hex to RGB shading codes into RGB design:

The RGB design has three qualities: Red, Green, and Blue.

Hex shading codes have a length of 6, i.e., they can contain 6 hex qualities (like BAFD32, AAFF22, and so forth)


Recollect when you were a youngster and had just 3 cups of acrylic paint, one of red, one of blue, and one of green? You blended contrasting measures of each paint together to make every one of the shadings you needed for your show-stopper.

RGB works in basically the same manner. Rather than blending paint notwithstanding, we are blending light.

RGB numbers depend on-screen settings which transmit red, green, and blue light. Through these numbers, you're let your screen know the amount of that specific light shading you need to sparkle.

Utilizing Colors

Your PC screen, iPhone, TV, and other gadget screens generally yield utilizing those equivalent tones, in changing sums. Each shade of the RGB model is addressed by numbers somewhere in the range of 0 and 225 for every red, green, and blue worth.

This lets a screen know how much result of each tone to utilize. Zero is the most reduced measure of shading utilized, and 255 is the most noteworthy. Assuming you add no shading in RGB (0,0,0) you get dark. Utilizing the most extreme.

Defining Colors

A large portion of you have presumably found out about CMYK esteems for print plans. RGB, which represents red, green, and blue is the shading model that screens use. Since in website architecture we're principally worried about what site pages resemble on screens, RGB is the shading model we use.

- RGB tones have three qualities that address: red, green, and blue.
- Each worth can be a number somewhere in the range of 0 and 255 or a rate from 0 to 100%.
- A worth of 0 methods no part of that tone is being utilized.
- A worth of 255 or 100% methods all of that tone is being utilized.
- A 0 for each of the three shadings esteems will be dark.
- A 255 or 100% for each of the three shadings esteems will be white.

Converting Hex to RGB

We will use the following approach to convert hexadecimal color codes to RGB format:

- The RGB format has three values: Red Green and Blue.
- Hexadecimal color codes are of length 6 that is they can contain 6 hexadecimal values (like BAFD32 AAFF22 etc.).
- We need to take two hex values for one RGB value convert those two hex values to decimal values and then do the same step with other values.
- We will get 3 values corresponding to the RGB values.
- Let’s see how this can be done in code.


- In line 1 we define a hex_to_rgb() function that accepts hexadecimal color code values.
- In line 3 we run a loop that gets two hex values from the color code at the same time.
- On line.
- We convert the two hex values to their decimal representation y specifying the radix as 16 in the int() function.
- Finally on line 7 we return the result in tuple format.

Now let’s see how we can convert RGB values to their hexadecimal representation.

Converting RGB to Hex

To convert RGB values to hexadecimal values we will take three RGB values and convert them to hexadecimal representation using: X while returning hexadecimal value. Now let’s see the code.


- On line 1 we define a function RGB to hex that takes three RGB values.
- On line 2 we generate the hexadecimal values using the {:X} formatter to automatically convert the decimal values to hexadecimal values. Then we return the result.

Finally, on line we call the function and pass the RGB values.

Share It


Branson Tachao

Branson Tachao is a bloggar and digital marketing executive at Tech company.