Color Converter (HEX, RGB, HSL)→Specialized Version
🎨

RGB to HEX Converter

Convert RGB to HEX

RGB in
rgb(59, 130, 246)
HEX out
#3B82F6
RGB
HSL

All formats

Lightness variations

RGB to HEX Converter

Convert RGB (Red, Green, Blue) color values to HEX color codes. HEX is the standard format for colors in web development, CSS, and HTML. This converter translates RGB values instantly to their hexadecimal equivalents.

Understanding the Conversion

RGB uses decimal values (0-255), while HEX uses hexadecimal (00-FF). Each RGB component converts to a two-character HEX value:

RGB ValueHEX Value
255FF
12880
000
200C8

Conversion Formula

To convert RGB to HEX: 1. Convert each decimal value (0-255) to hexadecimal (00-FF) 2. Combine as #RRGGBB

Example: rgb(255, 128, 64)

  • 255 → FF
  • 128 → 80
  • 64 → 40
  • Result: #FF8040

Common RGB to HEX Conversions

ColorRGBHEX
Redrgb(255, 0, 0)#FF0000
Greenrgb(0, 255, 0)#00FF00
Bluergb(0, 0, 255)#0000FF
Yellowrgb(255, 255, 0)#FFFF00
Cyanrgb(0, 255, 255)#00FFFF
Grayrgb(128, 128, 128)#808080

Using HEX in CSS

``css .element { color: #FF5733; background-color: #F0F0F0; border-color: #333333; } `

Shorthand HEX

When each pair has identical digits, use 3-character shorthand:

  • #FF0000 → #F00
  • #336699 → #369
Use this converter for quick RGB to HEX translation in your web projects.

RGB and HEX

RGBHEX
Syntaxrgb(255 99 71) in modern CSS, rgb(255, 99, 71) in the legacy comma form#RRGGBB, or #RGB shorthand, or #RRGGBBAA with alpha
Channelsred, green, blue — 0–255 or 0–100%red, green, blue — each 0–255 written as two hex digits
Precision8 bits per channel as normally written; CSS accepts fractional values8 bits per channel, 16.7 million colours
SupportUniversal. The space-separated form needs a 2020-or-later browser.Universal. The 8-digit alpha form needs a 2020-or-later browser.
Best forProgrammatic colour manipulation, canvas work, image pixel data.Design handoff, CSS, anywhere a colour is written as a single token.

A Worked Example

Taking CSS tomato through every format:

FormatValue
HEX#FF6347
RGBrgb(255, 99, 71)
RGBArgba(255, 99, 71, 0.5)
HSLhsl(9, 100%, 64%)
HSBhsb(9, 72%, 100%)
CMYKcmyk(0%, 61%, 72%, 0%)

Doing It in Code

`javascript // HEX to RGB const hexToRgb = (hex) => { const n = parseInt(hex.replace('#', ''), 16); return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255 }; };

// RGB to HEX const rgbToHex = (r, g, b) => '#' + [r, g, b].map((v) => v.toString(16).padStart(2, '0')).join(''); `

Modern CSS can do a lot of this without any conversion at all: color-mix() blends two colours, and relative colour syntax — hsl(from var(--brand) h s calc(l + 10%))` — derives a lighter shade without you ever computing one.

Frequently Asked Questions

What is RGB when working with RGB to HEX?

Red, Green, Blue values from 0-255 that combine to create colors on screens.

Why use HEX when working with RGB to HEX?

HEX is more compact and the standard in web development (HTML, CSS).

Can all RGB colors be expressed in HEX?

Yes, RGB and HEX represent the exact same color space.

Related Tools

Explore other tools you might find useful:

More Color Converter (HEX, RGB, HSL) tools

You might also need