Skip to content
colors

invert

The `invert` function returns the inverse (complement) of a HEX color by subtracting each RGB component from 255. This produces the color opposite on the RGB spectrum.

1 min read109 words

Function Signature

js

invert(hex: string): string

Parameters

  • 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.

Previous

adjustHue

Next

mix


Top-Werkzeuge

BoardlyLinksyChromoCodeHub

ReadyTools

KarriereKontaktWerkzeuge
Preise7 Tage gratis
AnleitungenDocsBlogUpdatesLaraVault

Sprache wählen

Thema wählen

© 2026 ReadyTools. Alle Rechte vorbehalten.