RGB to hex converter
Get the hex code for any RGB color: 255, 128, 0 is #ff8000, an orange. The six digits come in lowercase, uppercase and without the hash, ready for a stylesheet or a brand guide. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Resistance (Ω)
- 255
- G
- 128
- B
- 0
- Hex
- #ff8000
- Hex no hash
- ff8000
- Uppercase
- #FF8000
- Rgb
- rgb(255, 128, 0)
This RGB to hex converter takes three channel intensities—red, green, and blue—each as an integer from zero through two hundred fifty-five, and returns the matching CSS hexadecimal color string such as hash ff eight zero zero zero for orange. Designers, front-end developers, and students use this mapping every day: design tools export sRGB triples, stylesheets and tokens prefer compact six-digit hex, and handouts need a reproducible bridge between the two. The engine is fully deterministic: it splits each channel into high and low nibbles with floor division by sixteen and remainder, maps each nibble to a digit from zero through nine and a through f, and never calls the network, samples randomness, or depends on the clock.
How RGB becomes a hex color code
In the eight-bit sRGB model used by CSS and most web graphics, each of red, green, and blue is an integer channel from zero (none of that primary) through two hundred fifty-five (full intensity). Hexadecimal color codes pack the same three bytes into six hex digits: two digits for red, two for green, and two for blue, usually written with a leading hash so a stylesheet can use them as a color value.
Conversion is the classic nibble split: for a channel n, the high digit is floor of n over sixteen and the low digit is n modulo sixteen; each digit maps to zero through nine then a through f. There is no path that accepts percentages, floating-point channels, or three-digit shorthand as input, and no silent clamp of two hundred fifty-six down to two hundred fifty-five.
How r, g, and b are read and how the hex stays reproducible
Outer whitespace on string channels is trimmed; an optional leading plus is allowed only when the remaining characters are decimal digits that parse to an integer in range. A bare JavaScript number is accepted only when it is a finite integer inside zero through two hundred fifty-five; values such as one hundred twenty-eight point five fail validation rather than being rounded, and negative or two-hundred-fifty-six-plus values fail with a message that names the channel and states that it must stay inside zero through two hundred fifty-five.
Conversion uses the fixed digit alphabet zero through nine and a through f on each nibble so the same triple always yields the same lowercase hex string across runs and platforms. Zero maps to zero zero, two hundred fifty-five maps to f f, and mixed channels such as forty-three, ninety-eight, eighty-one produce the familiar two-b six-two five-one pattern used in design systems.
Where RGB-to-hex conversion fits in design, study, and software
Designers meet this mapping when a brand guide lists RGB swatches and the CSS or Figma token file needs hash codes, when a screenshot eyedropper reports red green blue and the theme file stores hex, or when a accessibility check must echo the same color string the stylesheet uses. Students see it in web-development courses that introduce CSS colors, in digital art classes that move between channel sliders and hex pickers, and in interview warm-ups that ask for a mental convert of a short triple.
Product and education tools use the conversion when a learner adjusts three sliders and the UI must show the live hex string without a round-trip to a heavy graphics library. Pair it with multi-format color tools when you need HSL or CMYK, and with other free deterministic converters when you are building a small lab for design-system hygiene.
What you can do with it
Design tokens and CSS
Turn brand RGB triples into #rrggbb strings for stylesheets, theme files, and design-system tokens.
Homework and teaching demos
Check student channel-to-hex work and live-demo CSS colors without opaque calculator apps.
FAQ
What does the RGB to hex converter cost?
It is free in your browser on this page.
What range is allowed for r, g, and b?
Each channel must be an integer from 0 to 255 inclusive.
Is the hex output lowercase or uppercase?
The primary hex field uses lowercase digits with a leading #. The uppercase field returns the same color with capital A–F for style guides that prefer that form.
Does this convert hex back to RGB?
No. This tool only maps integer RGB channels to a hex string. Use a multi-format color converter if you need hex-to-RGB or other spaces.
Can I enter decimals or values above 255?
No. Each channel must be a whole number from 0 to 255. A decimal or a number above 255 is rejected with a message naming the channel, rather than being rounded or clamped.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/color/rgb-hex \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"r":255,"g":128,"b":0}'const res = await fetch("https://api.kit.forhosting.com/color/rgb-hex", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"r": 255,
"g": 128,
"b": 0
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/color/rgb-hex",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"r": 255,
"g": 128,
"b": 0
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/color/rgb-hex", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"r":255,"g":128,"b":0}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"r":255,"g":128,"b":0}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/color/rgb-hex", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"r": 255,
"g": 128,
"b": 0
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "color.rgb_hex",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
min_channel | 0 |
max_channel | 255 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Channels outside zero through two hundred fifty-five are rejected with a clear invalid_input error rather than silently clamped.
What RGB-to-hex conversion means and what the response contains
This calculator returns the validated integers r, g, and b, a lowercase hex string with the leading hash, the same six digits without the hash, an uppercase hash form for style guides that prefer capital A through F, an rgb function string such as rgb of two five five comma one two eight comma zero, a method tag rgb_to_hex, and a short formula reminder of the nibble mapping. The engine either builds an exact six-digit hex for three legal channels or rejects the request with invalid_input. Rejected cases include a missing r, g, or b field, empty strings after trimming, non-integer numbers, non-numeric text, Infinity or NaN, and any channel strictly below zero or above two hundred fifty-five.
How r, g, and b are read and how the hex stays reproducible
The preferred fields are r for red, g for green, and b for blue, but aliases red and capital R for red, green and capital G for green, and blue and capital B for blue are accepted so spreadsheets, query strings, and typed forms can reuse the same contract without renaming columns. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing channel packing yourself.
Where RGB-to-hex conversion fits in design, study, and software
On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a classroom demo or design review to an automated pipeline without changing the mathematical result.
Integration use cases
Deterministic test fixtures
Generate reproducible hex results for unit tests, property checks, and CI assertions on color helpers.
Technical questions
Why is 256 rejected instead of clamped?
Silent clamping hides data errors. Out-of-range channels fail with invalid_input so callers fix the source values instead of publishing the wrong color.