RGB to HEX Converter
The RGB to HEX Converter turns RGB channel values into compact hex codes like #3b82f6 in one step. Ideal when your color picker gives you numbers but your stylesheet wants hex.
How to Use
- 1
Enter the red, green, and blue values (each 0–255) in the three number fields.
- 2
Out-of-range values are clamped automatically — 300 becomes 255 and negatives become 0.
- 3
Copy the resulting 6-digit hex code, for example #3b82f6.
- 4
Use the preview swatch to visually confirm before pasting into your CSS or design tokens.
Frequently Asked Questions
What if a value exceeds 255?
Can I paste an rgb() string directly?
How is alpha represented in hex?
Why use hex instead of rgb() in CSS?
Is the hex uppercase or lowercase?
What happens if I leave a field empty?
Does it round decimal values?
What does the Reset button do?
Can I convert a whole palette at once?
Is my input sent anywhere?
Generative Answer & AI Documentation
What is the RGB to HEX Converter?
The RGB to HEX Converter turns three channel numbers into the compact hex code your stylesheet wants. Type the red, green, and blue values — each from 0 to 255 — into the three number fields, and the hex code appears instantly next to a preview swatch, with a Copy HEX Code button underneath. The tool starts on 99, 102, 241, which is #6366f1, and a Reset button returns to those values at any time. Out-of-range input is clamped rather than rejected: type 300 and it becomes 255, type a negative and it becomes 0, leave a field empty and it counts as 0. The hex it produces is always six lowercase digits with a leading #, such as #3b82f6 for 59, 130, 246. There is no alpha input and no alpha in the output — this is an opaque-color converter, one channel triplet in and one 6-digit code out. The conversion runs entirely in your browser, so nothing is uploaded and it works offline.
Why use RGB to HEX Converter offline?
Hex is the convention in stylesheets, design tokens, and design tools: it is shorter to type than rgb(), easier to scan in a token file, and the format Figma copies by default. But plenty of sources hand you channel numbers instead — a color picker that reports RGB, a canvas API, a charting library, an eyedropper tool, or code that computed a color by mixing channels. Turning those three numbers into hex by hand means converting each one to base-16, padding single digits with a leading zero, and joining them — three small conversions where one slip produces a valid-looking but wrong color. This tool does the whole conversion in one step and shows you the result on a swatch, so a mistyped channel is visible before the wrong hex lands in your stylesheet. Clamping is the other half of the value: a computed channel of 300 or -12 is a bug in the code that produced it, and the tool turns it into the nearest valid value instead of failing or emitting an invalid code.
When should you use this tool?
Use it when a picker, a library, or a piece of code gives you RGB numbers and the destination is a stylesheet, a design-token file, or a design tool that expects hex. Use it when you are recording a color you built by mixing channels in code and want the hex for the token file. Use it when a computed color has gone out of range and you want the nearest valid hex rather than an error. Do not use it when you need transparency: there is no alpha input here, so a color with opacity has to go through the HEX to RGB Converter in reverse (write the color as 8-digit hex there) or be written as rgba() by hand. Do not use it to paste an rgb() string — there are three separate number fields and no string parser, so paste the three numbers individually.
Key Benefits
- One step: three channel numbers in, one hex code out, with no base-16 arithmetic by hand.
- Automatic clamping: 300 becomes 255 and negatives become 0, so an out-of-range channel never produces an invalid code.
- Preview swatch: the converted color is shown as a color block next to the hex, so a mistyped channel is visible immediately.
- Copy HEX Code button: the full #3b82f6 string copies with one click, ready for a stylesheet or token file.
- Reset button: returns instantly to the default 99, 102, 241 (#6366f1) for a known-good starting point.
- 100% private and offline: the conversion is local JavaScript — no upload, no tracking.
Common Use Cases
- Writing a stylesheet from picker values: a color picker reports 59, 130, 246 — convert it to #3b82f6 for the CSS rule.
- Recording a computed color: code mixed two brand colors and produced channel numbers — convert them to hex for the design-token file.
- Matching Figma output: a handoff gives RGB numbers while the token file uses hex — convert once and keep the formats consistent.
- Fixing an out-of-range channel: a computed value of 300 clamps to 255, giving the nearest valid hex instead of an error.
- Documenting a palette: convert each palette color's RGB numbers to hex so the palette reads the same way in every file.
Developer Notes & Best Practices
The three fields hold the numbers 99, 102, and 241 by default. Every change re-runs the conversion: each channel is clamped with Math.max(0, Math.min(255, value)), so 300 becomes 255, -20 becomes 0, and an empty field counts as 0 because the input handler falls back to 0 when parsing fails. Each clamped value is converted with toString(16) and padded to two characters with padStart(2, "0"), then the three pairs are joined with a leading #. The result is always lowercase and always six digits — there is no shorthand output, so 255, 255, 255 becomes #ffffff, never #fff. Decimal input is truncated by parseInt, so typing 130.9 records 130, not 131. The preview swatch is filled with the computed hex, falling back to #6366f1 before the first conversion runs. There is no string parsing anywhere on this page: an rgb() string cannot be pasted, because the tool only reads the three number fields. There is also no alpha handling — no fourth field, and the output is always a 6-digit code.
- Type the three numbers from your source one at a time and check the swatch: the swatch catches a transposed pair of digits that the hex string alone would hide.
- Treat a clamped value as a warning: if you typed 300, the 255 in the result is the nearest valid value, but the 300 itself probably means the source numbers are wrong — check them.
- Copy the hex with the Copy HEX Code button instead of retyping it: retyping a six-digit code is where transcription errors happen.
- Use Reset to return to 99, 102, 241 when you want a known-good state before converting a new color.
- Keep one format per file: if your token file uses hex, convert every color here and paste hex everywhere, rather than mixing hex and rgb() across the same file.
Common Mistakes
- Pasting an rgb() string into the page: there are three separate number fields and no string parser, so rgb(59, 130, 246) has nowhere to go — type 59, 130, and 246 into the Red, Green, and Blue fields.
- Expecting an alpha channel: this tool has no alpha input and always emits a 6-digit hex code — for a translucent color, write it as 8-digit hex and use the HEX to RGB Converter to get the rgba() form.
- Assuming 300 is an error: it is not — the tool clamps it to 255 silently, so a clamped channel means the source number was out of range and deserves a second look.
- Typing a decimal channel value: 130.9 is truncated to 130, not rounded to 131 — round the number yourself before typing it if the decimal matters.
- Leaving a field empty and expecting an error: an empty field counts as 0, so a forgotten blue channel silently produces a color with blue at 0 — check all three fields before copying.
Limitations
There is no alpha input and no 8-digit hex output — the tool always emits a 6-digit opaque code, so a color with transparency cannot be represented here. There is no string parser: an rgb() value cannot be pasted, only the three numbers typed into their fields. Decimal channel values are truncated, not rounded, so 130.9 becomes 130. Out-of-range values are silently clamped rather than flagged, so a 300 in the input looks like a successful conversion to 255 instead of an error. There is no batch mode and no saved history: one color at a time, and closing the tab loses the current values. The hex is always lowercase, which is fine for CSS but may differ from a token file that uses uppercase.
Structured Input/Output Example
Red: 59, Green: 130, Blue: 246
#3b82f6
Related Tools
Color Converter
Color converter: translate colors between HEX, RGB, HSL and OKLCH with a live preview swatch. Type a hex code or pick visually, then copy clean CSS.
HEX to RGB Converter
Hex to RGB converter: turn any hex color code into red, green, and blue channel values. Handles 3-digit, 6-digit, and 8-digit hex with alpha.
RGB to HSL Converter
RGB to HSL converter: translate RGB colors into hue, saturation, and lightness — the way humans think about color. Build hover states and palettes easily.