RGB to HEX
Convert rgb() colours to HEX codes.
#00E5FF
How to use RGB to HEX
What is the rgb() function?
rgb() is the canonical CSS functional notation for an sRGB colour,
written with three decimal channel values from 0 to 255 — for example
rgb(255, 0, 0) for red. Each channel represents the intensity of
one of the three additive primaries: red, green and blue. Mix all
three at full strength and you get white (rgb(255, 255, 255)); set
them all to zero and you get black. The notation has been in CSS
since the very first colour module and is the form most often emitted
by JavaScript colour libraries, design-token systems and any tool
that thinks of colour as three integers rather than a packed string.
What is a HEX colour?
A hex colour is a six-digit number written in base-16 (hexadecimal)
that encodes the same red, green and blue intensities as rgb() — just
packed into a compact string with a leading #. The first pair of
digits is the red channel, the middle pair the green channel, the
last pair the blue channel, each ranging from 00 (none) to FF
(255, full). So #FF0000 is rgb(255, 0, 0) — pure red. Hex has
been the dominant way to write colours in HTML and CSS since 1996
because it’s compact, deterministic and trivial to paste between
tools, design files and stylesheets.
The conversion math
Convert each decimal channel to a two-digit base-16 number. In
JavaScript that’s n.toString(16).padStart(2, '0'): 255 becomes
ff, 128 becomes 80, 26 becomes 1a, 0 becomes 00. Concatenate
the three pairs in red-green-blue order, prepend #, and you have
the hex string. So rgb(26, 176, 255) becomes #1AB0FF. The
padding step matters — without it, rgb(5, 5, 5) would render as
#555 (the three-digit shortcut for #555555, a medium grey)
instead of the correct #050505, an almost-black.
Use cases
CSS authoring. Most design files, brand books and CSS frameworks emit hex. If your code is producing decimal triplets — from canvas sampling, a colour-picker library or a JSON design token — and your stylesheet convention is hex, this converter is the bridge.
Design tokens and Figma round-trips. Figma’s UI shows hex by default, so when you read RGB values from a JavaScript build pipeline and want to drop them back into a design tool, hex is usually the shorter trip.
Embedded systems and microcontrollers. Hex literals are common
in C/C++ code that drives LEDs, e-ink displays and other low-level
colour APIs. Converting a designer-supplied rgb() value into a hex
literal (or the equivalent 0xRRGGBB integer) is the first step.
Email and CMS templates. Hex is universally supported across HTML email clients and content-management systems; if you’re templating a colour that started life as JavaScript output, the hex form is the safer paste.
Pitfalls
- Out-of-range channels. Values above 255 or below 0 aren’t valid rgb(); the converter clamps them and tells you it did. If you’re seeing clamps, your upstream source is producing values outside the 8-bit range — worth investigating.
- Float channels. Modern CSS allows percentages and floats in
rgb()(e.g.rgb(50%, 0%, 100%)orrgb(255.5 0 0)). This landing rounds floats to the nearest integer before encoding, which is what every browser does internally when emitting hex. - Alpha is dropped.
rgba(r, g, b, a)input loses its alpha channel here. Use HEX to RGBA (or the Color Converter) when alpha matters. - Named colours not accepted.
red,blue,dodgerblueand the other CSS named colours aren’t parsed by this landing — paste decimal triplets only.
How to use this RGB to HEX converter
- Paste your rgb() value into the input. The parens and commas are
optional;
255, 0, 0andrgb(255 0 0)both work. - The
#RRGGBBoutput and the colour swatch update live — there is no Convert button. - If a channel is out of range or a value isn’t a number, a friendly inline message points at the problem.
- Tap Copy to put the hex string on your clipboard.
Privacy
The conversion is a handful of lines of JavaScript running in your browser tab. No values are sent to a server, no analytics are attached to your colour data, and the page caches its small bundle on first load so it works fully offline afterwards.
Compatibility notes
Six-digit hex is supported by every browser ever shipped — there is
no compatibility floor to worry about. The output uses the classic
#RRGGBB form (uppercase by default) which is what design tools and
CSS linters expect. If you need the three-digit shortcut form
(#FFF instead of #FFFFFF), the Color Converter offers it as an
option; this landing always emits the full six-digit form because
it’s unambiguous and round-trips losslessly through every parser.
Frequently asked questions
What rgb() formats does this accept?
rgb(r, g, b) with parentheses and commas, and the bare triplet r, g, b (or even space-separated r g b). Whitespace doesn't matter, and the channel order is always red, green, blue. Each channel must be an integer from 0 to 255 — out-of-range values are clamped and a small note explains the clamp. For rgba() input with an alpha channel, use the sibling tools that preserve alpha; this landing outputs #RRGGBB only.Why is each channel encoded as two hex digits?
00–FF, which is 0–255 in decimal — exactly the range of an 8-bit colour channel. So 255 becomes FF, 128 becomes 80, 26 becomes 1A, and 0 becomes 00. The full hex string concatenates the red, green and blue pairs in that order, producing #RRGGBB. The converter pads single-digit results (so 5 becomes 05, not 5) so the output is always exactly six digits after the hash.Will I get uppercase or lowercase hex?
#1AB0FF) because that's the convention emitted by most design tools — Figma, Sketch, Photoshop and Adobe XD all use uppercase. If your stylesheet convention is lowercase, just lowercase the string in your editor; the value is identical. CSS, browsers and every parser treat #1ab0ff and #1AB0FF as the same colour.What about rgba() with an alpha channel?
rgba(r, g, b, a) string, the alpha is dropped and you get #RRGGBB. For alpha-preserving output (#RRGGBBAA), use the HEX to RGBA landing for the reverse direction, or the Color Converter for full round-tripping with alpha intact.Is my colour data uploaded anywhere?
Related tools
HEX to RGB
Convert HEX colour codes to rgb() values.
RGB to HSL
Convert rgb() colours to hsl() for tints and shades.
HEX to RGBA
Convert HEX (including 8-digit hex-with-alpha) to rgba().
Color Converter
Convert colors between HEX, RGB, HSL, HSV, and CMYK.
WCAG Contrast Checker
Check color contrast against WCAG AA and AAA.
RGBA to HEX Converter
Convert RGBA colors into 8-digit HEX with alpha.