Skip to content

Examples

Quick examples for common use cases with the Color API.

const response = await fetch(
"https://color.koval.dev/v1/convert?value=%23ff0000",
{ headers: { Authorization: "Bearer YOUR_API_KEY" } },
);
const data = await response.json();
console.log(data.formats.rgb); // { r: 255, g: 0, b: 0 }
const response = await fetch("https://color.koval.dev/v1/analyze", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
foreground: "#000000",
background: "#ffffff",
}),
});
const data = await response.json();
console.log(data.accessibility.wcag.contrast_ratio); // 21
const response = await fetch(
"https://color.koval.dev/v1/name?value=%23ff0000&limit=3",
{ headers: { Authorization: "Bearer YOUR_API_KEY" } },
);
const data = await response.json();
console.log(data.matches);
// [{ name: 'red', hex: '#ff0000', dataset: 'css' }, ...]
const response = await fetch(
"https://color.koval.dev/v1/palette?value=%236366f1&type=complementary",
{ headers: { Authorization: "Bearer YOUR_API_KEY" } },
);
const data = await response.json();
console.log(data.palette);
// [{ hex: '#6366F1', oklch: {...} }, ...]

See the API Reference for all available endpoints.