Color Format Conversion
Convert color values between HEX, RGB, HSL, and CMYK formats. Every response includes all four representations so you never need to call more than once.
Overview
Use Cases
- Convert design tool color exports into CSS-ready values
- Build color palette generators and pickers
- Normalize color inputs from different user sources into a single format
- Populate design system tokens from brand color values
- Inspect color relationships between HEX codes and their HSL equivalents
Features
Converts between HEX, RGB, HSL, and CMYK in a single call
Returns all four formats simultaneously β no need for multiple requests
Accepts shorthand HEX notation (e.g. "#f53" β "#ff5533")
Flexible input parsing β whitespace-tolerant for rgb() and hsl() strings
Zero external dependencies β fast, in-memory conversion
API Endpoints
Convert Color
Convert a color value from one format to another. The response always includes all four formats.
GET
https://api.requiems.xyz/v1/convert/color
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| from | string |
Required | Source color format: hex, rgb, hsl, or cmyk |
| to | string |
Required | Target color format: hex, rgb, hsl, or cmyk |
| value | string |
Required | Color value in the source format (e.g. #ff5733, rgb(255,87,51), hsl(11,100%,60%), cmyk(0%,66%,80%,0%)) |
Try it out
Live DemoRequest
Source color format: hex, rgb, hsl, or cmyk
Target color format: hex, rgb, hsl, or cmyk
Color value in the source format (e.g. #ff5733, rgb(255,87,51), hsl(11,100%,60%), cmyk(0%,66%,80%,0%))
Sending request...
Response Fields
| Field | Type | Description |
|---|---|---|
| input | string |
The original value passed in the value parameter |
| result | string |
The color expressed in the requested to format |
| formats.hex | string |
HEX representation (#rrggbb) |
| formats.rgb | string |
RGB representation (rgb(r, g, b)) |
| formats.hsl | string |
HSL representation (hsl(h, s%, l%)) |
| formats.cmyk | string |
CMYK representation (cmyk(c%, m%, y%, k%)) |
Code Examples
# HEX to HSL
curl "https://api.requiems.xyz/v1/convert/color?from=hex&to=hsl&value=%23ff5733" \
-H "requiems-api-key: YOUR_API_KEY"
# RGB to CMYK
curl "https://api.requiems.xyz/v1/convert/color?from=rgb&to=cmyk&value=rgb(255%2C87%2C51)" \
-H "requiems-api-key: YOUR_API_KEY"
# HSL to HEX
curl "https://api.requiems.xyz/v1/convert/color?from=hsl&to=hex&value=hsl(120%2C100%25%2C50%25)" \
-H "requiems-api-key: YOUR_API_KEY"
import requests
url = "https://api.requiems.xyz/v1/convert/color"
headers = {"requiems-api-key": "YOUR_API_KEY"}
params = {"from": "hex", "to": "hsl", "value": "#ff5733"}
response = requests.get(url, params=params, headers=headers)
data = response.json()["data"]
print(data["result"]) # hsl(11, 100%, 60%)
print(data["formats"]["rgb"]) # rgb(255, 87, 51)
const params = new URLSearchParams({
from: 'hex',
to: 'hsl',
value: '#ff5733'
});
const response = await fetch(
`https://api.requiems.xyz/v1/convert/color?${params}`,
{ headers: { 'requiems-api-key': 'YOUR_API_KEY' } }
);
const { data } = await response.json();
console.log(data.result); // hsl(11, 100%, 60%)
console.log(data.formats.cmyk); // cmyk(0%, 66%, 80%, 0%)
require 'net/http'
require 'json'
uri = URI('https://api.requiems.xyz/v1/convert/color')
uri.query = URI.encode_www_form(from: 'hex', to: 'hsl', value: '#ff5733')
request = Net::HTTP::Get.new(uri)
request['requiems-api-key'] = 'YOUR_API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
data = JSON.parse(response.body)['data']
puts data['result'] # hsl(11, 100%, 60%)
puts data['formats']['hex'] # #ff5733
Error Responses
bad_request
One or more of from, to, or value parameters is missing or the from/to value is not one of: hex, rgb, hsl, cmyk.
invalid_color
The value cannot be parsed in the specified from format.
internal_error
Unexpected server error.
Frequently Asked Questions
Yes. The formats object always contains hex, rgb, hsl, and cmyk regardless of the to parameter. The to parameter only controls which format appears in the top-level result field.
hex accepts #rrggbb or shorthand #rgb (which is expanded to #rrggbb). rgb accepts rgb(r, g, b) with or without spaces. hsl accepts hsl(h, s%, l%). cmyk accepts cmyk(c%, m%, y%, k%). All percentage signs are required for hsl and cmyk.
Conversions that go through an RGB intermediate (all conversions here do) can have minor rounding differences on round-trips because RGB components are integers in [0, 255]. For example, converting a HEX value to HSL and back may produce a HEX value that differs in the last digit due to integer rounding.
No. The current implementation supports opaque colors only (HEX, RGB, HSL, CMYK without an alpha channel). RGBA, HSLA, and HEX8 are not supported.