Skip to content
colors

hexToCmyk

The `hexToCmyk` function converts a HEX color string into CMYK components. It is especially useful for print workflows, where CMYK is the standard color model.

1 min read126 words

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 hexToRgb for conversion.
  • Values are expressed in percentages rather than fractional values.

Previous

rgbaToHexA

Next

rgbToHsl


Top eszközök

BoardlyLinksyChromoCodeHub

ReadyTools

KarrierKapcsolatEszközök
Árak7 nap ingyen
ÚtmutatókDocsBlogUpdatesLaraVault

Nyelv kiválasztása

Téma beállítása

© 2026 ReadyTools. Minden jog fenntartva.