RGB to Hex Converter
Convert RGB/RGBA functional color values to standard 3, 6, or 8-digit Hexadecimal strings.
When a System Wants Hex Instead of RGB
An RGB to hex converter changes the notation of three 8-bit color channels. It is useful when browser devtools show rgb(59, 130, 246) but a design token file, CMS field, email template, or graphics setting expects #3b82f6. The color itself stays the same; only decimal channel notation becomes hexadecimal.
Type a value into RGB Color Format (R, G, B). When the component can extract three valid channel numbers from 0 through 255, it updates the preview and Hexadecimal Conversion output. Copy writes the six-digit lowercase hex value to the clipboard.
This is a deliberately small converter. It does not expose separate red, green, and blue sliders. It does not offer three-digit compression, eight-digit alpha output, or uppercase formatting. Understanding its parser is especially important because it is more permissive in some ways and more limited in others than a full CSS color parser.
Conversion by Channel
Decimal 59 divided into hexadecimal gives 3b; 130 gives 82; and 246 gives f6. Padding ensures each channel occupies exactly two characters, so decimal 0 becomes 00 and decimal 5 becomes 05. Joining the channels in RGB order produces #3b82f6.
Several anchor values make manual review easier:
| RGB input | Hex output | Interpretation |
|---|---|---|
rgb(0, 0, 0) |
#000000 |
black |
rgb(255, 255, 255) |
#ffffff |
white |
rgb(255, 0, 0) |
#ff0000 |
red |
rgb(0, 128, 0) |
#008000 |
CSS green |
rgb(32, 32, 32) |
#202020 |
dark neutral gray |
The output always has six digits. Even when #ffffff could be abbreviated as #fff, the tool does not shorten it. Six-digit output is clearer for token generation and avoids introducing a separate compression rule.
The Parser: Useful Flexibility and Sharp Edges
The input logic extracts digit sequences with a regular expression and uses the first three as red, green, and blue. This means all of the following can supply channel numbers:
rgb(59, 130, 246)
59, 130, 246
R: 59 G: 130 B: 246
The field label recommends RGB form, and canonical rgb(r, g, b) is the safest input. The parser is not a standards-complete CSS parser. It does not understand percentages as percentages, decimals as decimals, negative signs, mathematical functions, or color-space keywords.
For example, rgb(100%, 0%, 0%) yields extracted numbers 100, 0, and 0, producing #640000 rather than red. rgb(12.5, 20, 30) extracts 12, 5, and 20 as its first three sequences, which shifts the channels. A leading minus sign is ignored, so negative text can be misread as positive digits. Do not use those forms.
RGBA deserves special caution. rgba(59, 130, 246, 0.5) contains at least three numbers, so the first three RGB channels convert correctly and alpha is silently ignored. That may be acceptable when intentionally extracting the opaque base color, but it is not an RGBA to eight-digit hex conversion. The output loses transparency.
A Safe Working Pattern
Normalize the source into three whole decimal integers. Verify that each lies between 0 and 255. Enter them in red-green-blue order using commas. Compare the preview against the source. Copy the six-digit result only after it changes.
Suppose a browser reports rgb(15, 118, 110). The converter returns #0f766e. The leading zero in 0f is significant: without it, channel boundaries would become unclear and the string would no longer be a valid six-digit representation.
For a CSS variable migration:
:root {
--brand-700: #0f766e;
}
For JSON, keep the hash inside the string unless the consuming API explicitly wants a bare six-character token:
{ "brandColor": "#0f766e" }
Hex colors that begin with # must be quoted in formats where # starts a comment, including many YAML contexts. Conversion does not protect against configuration-language syntax.
Invalid Values and Stale Results
Every extracted channel must be within 0–255. If one falls outside that range, if fewer than three numbers exist, or if the field is temporarily empty, the component does not show a validation message. It keeps the last valid hex output and preview.
That retention is convenient while editing but risky if overlooked. Entering rgb(300, 0, 0) after a valid blue leaves blue’s previous hex code visible. The output is not proof that the current input passed validation. Watch for a change and compare the preview before copying.
Values are converted with JavaScript number handling and toString(16). Whole integers are expected. Decimal forms can lead to unexpected token extraction before conversion rather than controlled rounding. If source channels are normalized floats from 0 to 1, multiply by 255 and round according to the source system before entering them.
Notation Is Not Color-Space Conversion
The tool assumes ordinary 0–255 RGB channel values suitable for a six-digit web hex color. It does not transform linear RGB to gamma-encoded sRGB, map Display P3 into sRGB, attach an ICC profile, or convert CMYK. Those operations require color-space definitions and may alter numeric channels to preserve appearance.
Likewise, a hex result does not automatically make a color accessible or brand compliant. Contrast depends on both foreground and background. Evaluate the final pair with an appropriate contrast checker, and review hover, disabled, and focus states separately.
The hex string contains no semantic information. #dc2626 could mean error, promotion, chart series three, or decorative red. Preserve token names and design intent during migration rather than replacing meaningful variables with raw literals everywhere.
Where Errors Usually Enter
Channel order gets reversed when values come from BGR image buffers. Percentage syntax gets treated as ordinary numbers. Alpha is silently dropped. A stale output is copied after an out-of-range edit. A leading zero is removed from a generated token. Decimal normalized channels are entered without scaling. Each failure can produce valid-looking hex that represents the wrong color.
A simple review is to identify the dominant channel. If the source has a much larger blue value, the preview should look blue. Equal channels should produce gray. Black requires all zeros, and white requires all 255s. These checks catch many transcription problems immediately.
When processing many colors, use a scripted, validated conversion rather than pasting records one by one. This page is best for individual values, spot checks, and understanding a mapping. It has no batch input, export table, history, or undo control.
If a copied value is destined for a URL fragment, template, or preprocessor, account for the hash character according to that context. The conversion is correct as displayed, but transport syntax may require quoting or encoding.
Audit what the number extractor sees
When a source string contains labels, inspect all digit runs from left to right because the component always consumes the first three. A prefix such as version 2: rgb(59, 130, 246) would make 2 the red channel and shift the intended values. Canonical rgb() input avoids that ambiguity. After conversion, verify each two-digit hex pair against its corresponding decimal channel and confirm the swatch’s dominant color. If correcting the input does not visibly update the result, one extracted channel may still be outside 0–255; the previous valid value remains stored until all three checks pass together.
RGB to Hex FAQ
Can I enter just 59, 130, 246?
Yes. The parser extracts the first three digit sequences, although the labeled rgb(59, 130, 246) form communicates intent more clearly.
Does it support RGB percentages?
No. Percentage signs are not interpreted semantically. Enter whole channels from 0 to 255.
What happens to alpha in an RGBA value?
The first three channels may convert, but alpha is ignored. The result is six-digit opaque hex, not #RRGGBBAA.
Why is the previous color still displayed after an error?
Invalid or incomplete input does not clear the stored result. Correct all three channels and verify that the preview and output update.
Can it generate three-digit hex?
No. Output is always lowercase #rrggbb, even when each pair could be compressed to one repeated digit.
Is rgb(0, 255, 0) the same as #00ff00?
Yes, as ordinary CSS sRGB notation. Note that CSS’s named green is darker at #008000; the full-intensity value is named lime in CSS.
Why should hex channels be padded?
Each channel must occupy two positions. Padding decimal 5 to 05 preserves the fixed red, green, and blue boundaries in the six-character string.
Can I paste output from a color picker?
Yes if it provides integer RGB channels. Remove or consciously disregard alpha, percentages, decimals, and non-sRGB profile information before relying on this converter.