6

The browser's default text highlight (selection) background color can be overridden, e.g.:

::selection {
  background: #ffb7b7;
}

And the color is browser/OS specific. Is there a way to read the browser's default value using JavaScript or Dart?

Community
  • 1
  • 1

2 Answers2

5

I would say that you can't.

Both getComputedStyle(yourElement, '::selection').backgroundColor and getComputedStyle(yourElement, '::-moz-selection').backgroundColor will return transparent as default value and browser won't override os's default.
(Worth to be mentioned that if you set it to transparent, default os' value will be overriden).

I don't think browsers have access to os default preferences, and if they do, they probably won't let any website access it it so easily.

Kaiido
  • 123,334
  • 13
  • 219
  • 285
2

As described at https://stackoverflow.com/a/39543711/3273929, you can use CSS system colors: https://www.w3.org/TR/2010/PR-css3-color-20101028/#css2-system, although they are deprecated, they do work.

Community
  • 1
  • 1
Mark VY
  • 1,489
  • 16
  • 31
  • 2
    While `Background` and `Highlight` *do* work, neither seems to actually match what I'm seeing in Chrome on Ubuntu. – mpen Aug 23 '17 at 19:54