Hex to grayscale by Rec. 709 luminance
Convert #3498DB to gray with Rec. 709 luminance: 0.2126 × red + 0.7152 × green + 0.0722 × blue gives 135.5774, which rounds to 136 and the neutral gray #888888. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Hex
- #3498DB
- Input hex
- #3498db
- Gray hex
- #888888
- Gray value
- 136
- Luminance
- 135.5774
This hex-to-grayscale converter turns one strictly formatted #RRGGBB color into a neutral gray with Rec. 709 luminance weights. It gives green the strongest influence, red the next strongest, and blue the least, matching perceived brightness more closely than a simple three-channel average. The response includes the normalized input, source RGB channels, unrounded luminance, rounded gray value, repeated-channel gray hex, and formula. Invalid shorthand, missing hashes, alpha channels, spaces, or non-hex characters are rejected clearly instead of being guessed or silently repaired.
Why Rec. 709 weights produce a useful gray
A mathematical average treats red, green, and blue as though each channel contributes equally to apparent brightness, but human vision does not respond to those primaries equally. Green usually appears much brighter than blue at the same numeric channel level, with red between them. This converter applies the Rec. 709 luma coefficients: 0.2126 for red, 0.7152 for green, and 0.0722 for blue.
The three weighted contributions are added, and the result is rounded to the nearest whole channel value. That value is repeated across red, green, and blue to form a neutral six-digit gray. The approach is especially useful when a design or software workflow needs a single perceptually sensible gray representative of an RGB color.
It avoids the obvious brightness distortions caused by a plain arithmetic mean while remaining transparent, fast, and easy to reproduce in another programming language. The response exposes both the calculated luminance and the final integer, so reviewers can distinguish the weighted result from the rounding step and audit the conversion without relying on a hidden image editor setting.
How to provide a color and interpret the response
Send an object containing one hex field, such as #3498db. Validation is intentionally strict: the value must be a string beginning with one hash followed by exactly six hexadecimal digits. Uppercase and lowercase digits are accepted, but three-digit shorthand, eight-digit alpha notation, a 0x prefix, embedded whitespace, surrounding whitespace, named CSS colors, and a hashless value are rejected.
This narrow contract makes automation safer because malformed data cannot be reinterpreted differently by another library. The formula field identifies the exact coefficients used.
Reliable uses, boundaries, and testing advice
For robust tests, include black and white boundaries, an already neutral gray, a green-heavy color, a blue-heavy color, uppercase input, and several invalid formats. Keep the original source token if reversibility matters, because grayscale conversion discards hue and cannot reconstruct the starting color. When comparing results from other tools, confirm their formula first: BT.601 coefficients, equal averaging, gamma-linear luminance, and custom design-tool settings can all produce different numbers while still being called grayscale.
This capability states its formula in every response so those differences remain explainable rather than mysterious.
What you can do with it
Normalize design tokens
Turn individual brand and interface hex tokens into stable gray equivalents for monochrome themes and design reviews.
Prepare monochrome chart colors
Convert chart-series colors into perceptually weighted neutral values for grayscale previews and print workflows.
FAQ
Which formula is used?
The converter calculates 0.2126R + 0.7152G + 0.0722B and rounds the result to the nearest integer.
Which hex formats are accepted?
Only a hash followed by exactly six hexadecimal digits: #RRGGBB. Letter case may be uppercase or lowercase.
Are shorthand or alpha hex colors accepted?
No. #RGB and #RRGGBBAA are rejected so the input contract remains unambiguous and strict.
Why can another grayscale tool return a different value?
It may use equal averaging, BT.601 coefficients, gamma-linear luminance, truncation instead of rounding, or another grayscale model.
What gray does #3498DB give with Rec. 709 luminance?
It gives #888888. With red 52, green 152 and blue 219, the weighted sum is 135.5774, which rounds to a gray value of 136, repeated in all three channels.
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/grayscale-luminance \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"hex":"#3498db"}'const res = await fetch("https://api.kit.forhosting.com/color/grayscale-luminance", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"hex": "#3498db"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/color/grayscale-luminance",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"hex": "#3498db"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/color/grayscale-luminance", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"hex":"#3498db"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"hex":"#3498db"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/color/grayscale-luminance", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"hex": "#3498db"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "color.grayscale_luminance",
"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.
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
Why Rec. 709 weights produce a useful gray
Because every coefficient and rounding rule is fixed, identical input always produces identical JSON.
How to provide a color and interpret the response
On success, input_hex contains a normalized lowercase version of the source. input_rgb separates the red, green, and blue bytes as decimal integers. luminance reports the weighted sum to four decimal places, while gray_value reports that sum rounded to the nearest integer. gray_hex formats the integer as a two-digit hexadecimal byte repeated three times. API automation costs $0.002 per successful request, and the same pure solve function supports the browser path. Validation failures use invalid_input, allowing callers to distinguish a bad color from an infrastructure problem and show a focused correction message to the person who supplied it.
Reliable uses, boundaries, and testing advice
Assert both gray_value and gray_hex so a future change in either rounding or formatting becomes visible.
Integration use cases
Build deterministic test fixtures
Generate auditable gray values for color utility tests without depending on a browser canvas or image library.
Technical questions
What does an API conversion cost?
Each successful API request costs $0.002. Browser execution is available without an API charge.