Feb 6, '25 02:00

How to convert HEX to RGB?

Colors in HEX format are most commonly used in HTML, CSS, and graphic design. But sometimes you need to convert them to RGB. HEX Format A HEX color code consists of # and six characters (for example, #FF5733). The first two characters represent the intensit...

Read post
Share
🔥 More posts
This content has been automatically translated from Ukrainian.

Colors in HEX format are most commonly used in HTML, CSS, and graphic design. But sometimes you need to convert them to RGB.

HEX Format

A HEX color code consists of # and six characters (for example, #FF5733). The first two characters represent the intensity of red, the next two represent green, and the last two represent blue.

How to Convert HEX to RGB Manually

A HEX code is a hexadecimal number, while in RGB each component is represented in decimal. To convert HEX to RGB:

  1. Split the HEX code into three parts: For example, #FF5733FF, 57, 33.
  2. Convert each part to decimal:
    • FF (red) = 255
    • 57 (green) = 87
    • 33 (blue) = 51
  3. Get the RGB value: rgb(255, 87, 51).

Example Code in JavaScript

function hexToRgb(hex) {
  hex = hex.replace(/^#/, "");
  if (hex.length === 3) {
    hex = hex.split("").map(c => c + c).join("");
  }
  let bigint = parseInt(hex, 16);
  return `rgb(${(bigint >> 16) & 255}, ${(bigint >> 8) & 255}, ${bigint & 255})`;
}
console.log(hexToRgb("#FF5733")); // rgb(255, 87, 51)

Converting HEX to RGB is not a complicated process. It is enough to know that HEX is just another format for representing color that can be easily converted to decimal. This is a useful skill for web developers and designers.

We have a separate page where you can convert HEX to RGB.

🔥 More posts

All posts
Feb 6, '25 02:00

How to convert RGB to HEX?

Colors in RGB format are used in CSS, graphic design, and programming. But sometimes you need to conve...

Feb 7, '25 02:00

What is HTML?

HTML (HyperText Markup Language) – is a markup language used to create web pages. It defines the struc...

Feb 7, '25 02:00

How to convert HWB to RGB?

Colors in HWB format are not often used in web design and programming. But sometimes it's necessary to...

Feb 7, '25 02:00

How to convert RGB to HWB?

If you need to convert RGB to HWB, you can use a formula that allows you to obtain hue (H), whiteness ...