Background on color perception:
Due to the nature of the human eye and visual processing by the brain, there’s an optical illusion that the same color will look different depending on the background.
It is known as the contrast effect, illustrated below — center rectangles are identical:
An illustration (and report) by NASA makes the effect of the background’s color even more obvious:
Source: NASA Color Usage Research Lab
(Note how the two upper-most colors in the second image appear the same, but are actually completely different.)
What about web design?
My question pertains to web design, specifically in this case, the color of link text on different backgrounds.
For a given color of text, how can one find the complementary color to make it appear the same on a certain background?
Let’s take a look at an example for this question:
Consider my example below, with yellow text
#FFF000on the following backgrounds:
- and grey
As expected, doesn’t look the same at all. (View and download .PSD file here.)
How can we make it look the same on all three? Clearly, the text on the white background needs to be a darker yellow, and the one on the grey needs hue/tone adjustments. (The surrounding text will also affect it — but that’s likely harder to account for.)
Can this perfect color somehow be calculated, based on the Hex, RGB or another system? That’s where the crux of this question lies, as it would be much more efficient than manually approximating.
It seems like you’re looking for the analogue of complementary colours, but in the lightness space rather than hue. As far I can tell, no such general mapping can exist.
Suppose you could compensate for the effect by assuming a linear correlation between the background and the foreground, so that as the background darkens the foreground text lightens by the same amount. I assume that hue remains fixed. There will always be a midpoint at which the background and the foreground share the same colour.
As an example, consider black on white. The converse lightness for the same hues is white on black, but if you tried to find a foreground for every intermediate background of the same hue, at the midway point you hit grey-on-grey and can’t see anything at all.
For much the same reason, I can’t see that any reasonably simple mapping — even a lossy one — can exist.