How to color text so it is visible against any background color?

I have a page (source) where I've got a grid with different colored lines. Is there something I can set the
color
of the text to so it'll always be visible?

I want something like
mix-blend-mode
difference
plus
filter
invert(100%)
from this article. I want the text color to be the inverse of the background, and not to invert the background.

I also have programmatic access to the hex version of the background color. I tried
color-mix
ing some, to no avail.
Screenshot_from_2024-04-04_07-43-24.png
Was this page helpful?