toHex
Convert a Color to a lowercase hex string: #rrggbb, or #rrggbbaa when alpha is below 1.
import { toHex } from '@pbroom/color-kit';index.ts:136function toHex(color: Color): string;Out-of-gamut colors are clipped per channel like toRgb.
Parameters
Returns
stringHex string with a leading #
Throws
- When any channel of
coloris not finite
Example
import { parse, toHex } from '@pbroom/color-kit';
toHex(parse('oklch(0.7 0.15 30)')); // → '#ed7665'
toHex(parse('rgb(59 130 246 / 0.5)')); // → '#3b82f680'