Enter a RGB value on the left to convert
What Is an RGB to HEX Converter?
An RGB to HEX converter takes three integer values — red, green, and blue channels each in the range 0–255 — and returns the equivalent hexadecimal colour code like #28396C used in HTML and CSS. Both formats describe the exact same colour; HEX is just shorter and more common in stylesheets. Designers and developers convert RGB to HEX whenever they pull a colour from a design tool that reports RGB values and need to paste it into a stylesheet, brand guide, or CMS.
RGB to HEX Converter Online — What This Tool Does
This free RGB to HEX converter takes any RGB triplet — rgb(40, 57, 108) or just 40, 57, 108 — and returns the equivalent 6-digit HEX code with a live colour swatch. Copy the HEX to your clipboard with one click. Runs entirely in your browser, no upload, no account.
How to Convert RGB to HEX
- Enter your three RGB values into the RGB input — accepts
rgb(R, G, B)or justR, G, B. - Each channel must be an integer from 0 to 255.
- See the equivalent HEX code appear instantly.
- A live colour swatch shows you the exact colour.
- Click Copy next to the HEX output to copy the CSS-ready string.
- Need the opposite direction? Click the HEX to RGB tab.
RGB to HEX Conversion Formula
RGB channels are decimal (0–255); HEX is hexadecimal (00–FF). To convert by hand, divide each channel by 16, take the integer and remainder, and write them in hex: 40 → 28, 57 → 39, 108 → 6C → #28396C. Pad single hex digits with a leading zero so each channel uses two characters. The result is always prefixed with # in CSS.
Common RGB to HEX Conversions
rgb(0, 0, 0)→#000000— pure blackrgb(255, 255, 255)→#FFFFFF— pure whitergb(255, 0, 0)→#FF0000— pure redrgb(0, 255, 0)→#00FF00— pure greenrgb(0, 0, 255)→#0000FF— pure bluergb(128, 128, 128)→#808080— middle grey
When to Use HEX Instead of RGB
- Brand guidelines — HEX is the de facto standard for documenting brand colours.
- CSS stylesheets — shorter, fewer characters, easier to scan.
- Design tools — Figma, Sketch, and Adobe XD all display HEX by default.
- CMS / no-code platforms — most colour pickers expect HEX input.
- Marketing materials — print designers and developers share HEX codes when handing off.
Tips & Tricks
- Lowercase or uppercase consistently —
#ff0033and#FF0033are identical. Match the style of the codebase you're pasting into. - 3-digit shorthand — if all three channels are double digits like
#FF0033, you can compress to#F03. Only works when each pair is identical. - RGB with alpha — for transparency, use
rgba(R, G, B, A)directly or convert to 8-digit HEX (#RRGGBBAA). - Check accessibility — paste the HEX into our Contrast Checker to verify WCAG contrast.
Related Tools
- HEX to RGB Converter — convert in the opposite direction
- Color Picker — pick a colour visually and get HEX, RGB, and HSL at once
- Contrast Checker — verify WCAG AA/AAA contrast for accessibility
- Color Scale Generator — derive tints and shades from a base colour
- CSS Gradient Generator — build CSS gradients between two colours
Is My Color Sent to a Server?
No. RGB to HEX conversion runs entirely in your browser using small JavaScript arithmetic. There is no upload, no log, no analytics on the colour values you enter. Conversions are instant and local.