If you want the
inverted color which affects both hue and lightness, a simple invert will do.
Just convert from hex to RGB and invert each channel,
R = R *-1 + 255
G = G *-1 + 255
B = B *-1 + 255
And then convert back to hex.
If you want the
opposite hue, without affecting lightness, the most straightforward way is to convert from hex to HSL and rotate the hue 180 degrees.
Convert from hex to HSL and rotate H 180 degrees.
H = H +180 % 360
And then convert back to hex.
Taken from here[^] .