Function Signature
js
hexToCmyk(hex: string): { c: number, m: number, y: number, k: number }Parameters
hex(string): The input HEX color string, either in shorthand (#rgb) or full (#rrggbb) format.
Return Value
An object containing the CMYK components as percentages (0–100).
js
hexToCmyk("#ff6600");
// { c: 0, m: 60, y: 100, k: 0 }
hexToCmyk("#000000");
// { c: 0, m: 0, y: 0, k: 100 }
hexToCmyk("#ffffff");
// { c: 0, m: 0, y: 0, k: 0 }Examples
js
// Bright blue
console.log(hexToCmyk("#00aaff"));
// { c: 100, m: 25, y: 0, k: 0 }
// Forest green
console.log(hexToCmyk("#228b22"));
// { c: 75, m: 0, y: 75, k: 45 }Special Cases
- Pure black (
#000000) returns{ c: 0, m: 0, y: 0, k: 100 }. - Pure white (
#ffffff) returns{ c: 0, m: 0, y: 0, k: 0 }. - All values are rounded to integers for practical use in print.
Usage Notes
- CMYK is primarily used in print workflows (cyan, magenta, yellow, key/black).
- The function internally uses
hexToRgbfor conversion. - Values are expressed in percentages rather than fractional values.