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 (W), and blackness (B). Previously, we considered the reverse conversion: How to convert HWB to RGB?. RGB Format Colors in RGB format consist of three comp...

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

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

Previously, we considered the reverse conversion: How to convert HWB to RGB?.

RGB Format

Colors in RGB format consist of three components:

  • R (Red) — from 0 to 255
  • G (Green) — from 0 to 255
  • B (Blue) — from 0 to 255

How to Convert RGB to HWB Manually

  1. Find the hue (H) using the RGB → HSL conversion.
  2. Calculate whiteness (W) and blackness (B).

JavaScript Code Example

function rgbToHwb(r, g, b) {
  r /= 255; g /= 255; b /= 255;
  
  let max = Math.max(r, g, b);
  let min = Math.min(r, g, b);
  let w = min;
  let bComp = 1 - max;

  let h = (max === min) ? 0 :
          (max === r) ? ((g - b) / (max - min)) * 60 + (g < b ? 360 : 0) :
          (max === g) ? ((b - r) / (max - min)) * 60 + 120 :
          ((r - g) / (max - min)) * 60 + 240;
  
  return [Math.round(h), Math.round(w * 100), Math.round(bComp * 100)];
}

console.log(rgbToHwb(51, 102, 255));

🔥 More posts

All posts
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 convert them to RGB. Let's see how to do this. HWB Format The HWB code con...

Feb 8, '25 02:00

How to convert CMYK to RGB?

CMYK and RGB are two different color models used for printing and digital displays, respectively. If y...

Feb 8, '25 02:00

How to convert RGB to CMYK?

RGB and CMYK are two main color models used for digital displays and printing, respectively. If you ar...

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 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 t...

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...