Search code examples
user-interfacetextcolorsbackgroundforeground

Automatically choose appropriate gray color for a given background color


I have a table in which the cells may contain normal and grayed-out text. The color for normal text is chosen dynamically according to this post in order to take account that the table's background color is theme-dependent. Now I'm wondering if there's any good way to determine an appropriate "gray" color based on the table's background, so that:

  • the "gray" is "really" gray when the background color is white or black
  • the grayed-out text is readable with all possible background colors
  • if possible, the grayed-out text should be distinguishable from normal text, and ideally look "paler", in the same way that gray is paler than black

Note: Other styles, such as strike-out, are not appropriate in my case, since the gray color is used to convey the idea of a table cell being "less important" than others, rather than being obsolete/unavailable/etc.


Solution

  • Well, your linked question selects only one of two text colors: it will be either black or white.

    Did you try to just use a "dark gray" when the text color is black, and a light gray when the text color is white?