RGB / Hex Color Converter

Convert between RGB (Red, Green, Blue) values and Hex color codes. Enter either format to get the other.

RGB to Hex

Enter RGB values above to see the Hex code.

Hex to RGB

Enter a Hex code above to see the RGB values.

Formulas

RGB → Hex:
Each channel (R, G, B) in range 0–255 is converted to a two-digit hexadecimal value and concatenated:
Hex = "#" + toHex(R) + toHex(G) + toHex(B)
Example: rgb(255, 128, 0) → #FF8000

Hex → RGB:
Each pair of hex digits is parsed as a base-16 integer:
R = parseInt(HH₁, 16),   G = parseInt(HH₂, 16),   B = parseInt(HH₃, 16)
Example: #FF8000 → rgb(255, 128, 0)

Hex Shorthand (#RGB):
Each single digit is doubled before parsing:
#F80 → #FF8800

Bonus — RGB → HSL:
Normalize channels: R' = R/255, G' = G/255, B' = B/255
max = max(R', G', B'),   min = min(R', G', B')
L = (max + min) / 2
S = (max − min) / (1 − |2L − 1|)   if max ≠ min, else 0
H depends on which channel is max (0–360°)

Assumptions & References

  • RGB channels are integers in the range 0–255 (8-bit per channel).
  • Hex codes follow the standard web format: #RRGGBB or shorthand #RGB.
  • The # prefix is optional in the Hex input field — it will be added automatically.
  • Decimal RGB inputs are rounded to the nearest integer before conversion.
  • HSL values are provided as a bonus for reference; Hue is in degrees (0–360), Saturation and Lightness are percentages (0–100%).
  • Reference: W3C CSS Color Level 4 Specification
  • Reference: MDN Web Docs — CSS color values

In the network