RGB to Hex Converter

Converting RGB (red, green, blue) values to hexadecimal colour codes is essential for web designers and developers. RGB values (0-255 for each channel) are intuitive for calculations and programming, while hex codes are the standard notation for colours in CSS and web design. The conversion is straightforward: convert each decimal RGB value to its hexadecimal equivalent and concatenate them with a # prefix. For example, RGB(255, 87, 51) becomes #FF5733. This converter transforms RGB values to hex instantly, and displays a live colour preview swatch so you can see the resulting colour. It also shows the HSL (hue, saturation, lightness) equivalent and CSS syntax for all three formats. Simply enter red, green, and blue values from 0 to 255, and the converter generates the hex code automatically.

#FF5733
HSL(10, 100%, 60%)

RGB to hex conversion formula

Convert each RGB value (0-255) to hexadecimal (00-FF) and combine with a # prefix:

  • Red: 255 = FF (hex)
  • Green: 87 = 57 (hex)
  • Blue: 51 = 33 (hex)
  • Result: #FF5733

Common RGB to hex conversions

Colour RGB Hex HSL
Red RGB(255, 0, 0) #FF0000 HSL(0, 100%, 50%)
Green RGB(0, 255, 0) #00FF00 HSL(120, 100%, 50%)
Blue RGB(0, 0, 255) #0000FF HSL(240, 100%, 50%)
Yellow RGB(255, 255, 0) #FFFF00 HSL(60, 100%, 50%)
Black RGB(0, 0, 0) #000000 HSL(0, 0%, 0%)
White RGB(255, 255, 255) #FFFFFF HSL(0, 0%, 100%)

RGB to hex converter: frequently asked questions

How do I convert RGB to hex?

Convert each RGB channel (red, green, blue) from decimal (0-255) to hexadecimal (00-FF). For example, RGB(255, 87, 51) converts to FF (255), 57 (87), and 33 (51), giving #FF5733.

What is the formula for RGB to hex conversion?

For each colour channel, convert the decimal value to hexadecimal and pad with a leading zero if needed. For example, 255 in decimal is FF in hex, 87 is 57, and 51 is 33. Combine them with a # prefix: #FF5733.

Why use hex instead of RGB?

Hex is more compact and has become the standard in web design and CSS. It is easier to read as a single string and is widely supported. However, RGB is more intuitive for programming and colour calculations.

Can I use short hex codes?

Yes, short hex codes like #F37 are shorthand for #FF3377 (each character is doubled). They work in CSS but are less precise. This converter outputs full 6-digit hex codes for clarity.

What is 8-digit hex?

8-digit hex codes add an alpha channel for transparency, written as #RRGGBBAA. This is called HEXA. For example, #FF573780 is the same colour as #FF5733 but at 50% opacity.

Official sources

Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.