-1

I noticed that as you change the theme-color meta tag, Chrome will choose an appropriate secondary color for the url bar and icons (either black or white) that will contrast with the chosen theme color.

Does anyone know how chrome calculates the second color?

I'd like to match the logic for a site header.

nihlton
  • 659
  • 6
  • 7
  • chrome is open source so you can track that down. – Daniel A. White May 24 '20 at 02:55
  • 'this can be answered elsewhere' is probably true for a lot of questions asked here, and not super useful. \ – nihlton May 24 '20 at 03:08
  • Not sure how accurate this is - but - used the calculation here : https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color/3943023#3943023 to check L values (L = (0.2126 * R) + (0.7152 * G) + (0.0722 * B)) to see where Chrome switched over from black to white. seems like the value is .3 ...which is significantly different from the recommended .179... need more testing... – nihlton May 24 '20 at 03:32

1 Answers1

0

Ok, i think I've got a usable answer.

Using this calculation >> https://stackoverflow.com/a/41491220/3394758

and changing the threshold from 0.179 to 0.3 seems to arrive at similar behaviors to Chrome.

tested with 255 gray values, and a handful of color values.

Your mileage may vary.

nihlton
  • 659
  • 6
  • 7