Function Signature
js
invert(hex: string): stringParameters
hex(string): A HEX color string (e.g.,#ff6600).
Return Value
A HEX color string representing the inverted color, always in the format #rrggbb.
js
invert("#ffffff");
// "#000000"
invert("#000000");
// "#ffffff"
invert("#ff6600");
// "#0099ff"Examples
js
// Invert bright blue
console.log(invert("#00aaff"));
// "#ff5500"
// Invert gray
console.log(invert("#808080"));
// "#7f7f7f"Implementation Details
- Converts the HEX input into RGB values using
hexToRgb. - Each channel is inverted with
255 - value. - The result is converted back into HEX with
rgbToHex.
Usage Notes
- Inverting twice returns the original color.
- Useful for generating contrasting colors for backgrounds and text.
- Produces a mathematically exact inverse, not a perceptual complement.