Blend two colors by ratio
This ratio color blender combines two hexadecimal colors using an exact percentage weight in RGB space.
Run — free
Supply the first color, the second color, and the percentage contribution of the second color. The calculator averages red, green, and blue independently, rounds each result to a valid channel integer, and returns both a normalized uppercase hex value and separate RGB numbers. It is useful when a design token, generated chart, theme, or automated asset needs a repeatable result rather than a color selected by eye. Invalid colors and ratios are rejected clearly, while identical inputs always return identical output.
Define the ratio before blending the colors
Treat the ratio as the percentage contribution of the second color. A ratio of zero gives all the weight to the first color, so the output equals color1. A ratio of one hundred gives all the weight to color2. At twenty-five, the first color contributes seventy-five percent and the second contributes twenty-five percent. This direction matters when a workflow creates several related swatches, because reversing the two inputs without also reversing the ratio changes the result. Enter either three-digit shorthand, such as #F00, or a complete six-digit hexadecimal value, such as #FF0000. The leading hash is optional, but every remaining character must be a hexadecimal digit. The tool deliberately rejects CSS names, RGB function strings, eight-digit alpha colors, missing fields, and malformed values instead of guessing. Explicit validation makes batch processing safer: a typo becomes an invalid input response at the affected record rather than silently producing a plausible but incorrect palette entry. Keep the input order documented in reusable scripts so later maintainers understand which endpoint of the blend owns the stated percentage.
Understand the weighted RGB calculation
The algorithm first converts each hexadecimal color into red, green, and blue channel values between zero and 255. For every channel it multiplies the first value by one minus the ratio fraction, multiplies the second value by the ratio fraction, adds those products, and rounds the sum to the nearest whole channel value. For example, a fifty-percent mix gives equal weight to both inputs, while a ten-percent mix remains much closer to the first. Red, green, and blue are calculated separately, so no random choice, lookup table, network request, or hidden palette rule affects the answer. This is a linear weighted average of encoded RGB channels. It is not a perceptual blend and does not convert through HSL, LAB, LCH, paint pigments, or gamma-linear light. Consequently, the visual midpoint between very different colors may not appear equally bright to a human observer. That behavior is intentional and useful when software needs the familiar arithmetic blend used by many token generators and graphics routines. The method field identifies the calculation, making stored results easier to audit if another mixing model is introduced elsewhere.
Use the result reliably in design and automation
The response provides the blended color as an uppercase six-digit hex string and as an RGB object containing integer red, green, and blue fields. It also echoes the ratio, reports both normalized weights, and names the method. Use the hex value directly in CSS variables, theme manifests, chart configuration, email templates, or design-token files. Use the separate channels when another program needs numeric input or when you want to pass the result to a contrast or luminance calculator. Because the calculation is deterministic and bounded, it works well in tests: a fixed request can be stored as a golden fixture and compared exactly on every run. The in-browser version is convenient for occasional palette work, while an API request costs $0.002 when a build pipeline, content system, or application needs the same behavior programmatically. Validate accessibility after blending when the output will sit behind text, because a mathematically correct ratio does not guarantee sufficient contrast. For a color ramp, call the capability with the same ordered pair and a planned sequence such as zero, twenty, forty, sixty, eighty, and one hundred; this preserves consistent endpoints and makes every intermediate swatch reproducible.
What you can do with it
Generate design-token steps
Create repeatable intermediate tokens between two approved brand colors using documented percentage weights.
Build chart color variants
Blend a series color toward a common background or accent without manually selecting every swatch.
Test themed interface states
Produce stable hover, selected, and disabled colors in automated theme-generation pipelines.
FAQ
What does the ratio represent?
It is the percentage weight of color2. The remaining percentage belongs to color1.
Which color formats are accepted?
Three- or six-digit hexadecimal colors are accepted, with or without a leading hash.
How are fractional channel results handled?
Each weighted RGB channel is rounded to the nearest integer using deterministic JavaScript rounding.
Is this a perceptual color blend?
No. It is a direct weighted average of encoded RGB channel values, not an HSL, LAB, or gamma-corrected blend.
How much does an API request cost?
The API base price is $0.002 per item; the browser tool can be used directly on the page.
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/mix-ratio \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"color1":"#FF0000","color2":"#0000FF","ratio":50}'const res = await fetch("https://api.kit.forhosting.com/color/mix-ratio", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"color1": "#FF0000",
"color2": "#0000FF",
"ratio": 50
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/color/mix-ratio",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"color1": "#FF0000",
"color2": "#0000FF",
"ratio": 50
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/color/mix-ratio", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"color1":"#FF0000","color2":"#0000FF","ratio":50}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"color1":"#FF0000","color2":"#0000FF","ratio":50}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/color/mix-ratio", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"color1": "#FF0000",
"color2": "#0000FF",
"ratio": 50
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "color.mix_ratio",
"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. |