div {
background-color: lightgreen;
max-height: 5em;
overflow-y: scroll;
scrollbar-color: lightgreen lightgreen;
}
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
Using scrollbar-color works (more info here). I think color detection is just really buggy – sometimes one color works with scrollbar-color and applies to both parts of the scrollbar and sometimes you need to repeat it twice. I just think it’s a poorly implemented part of the HTML spec. Doesn’t have great browser support though so make sure it’s not required as part of your interface.
TLDR; I’ve encountered interesting behaviour in Firefox. For example, it automatically styles the scrollbar limegreen, but not lightgreen. Why does it render one, but not the other?
While answering another question I found that this renders a limegreen colored scroll bar in Firefox 72 latest on Windows 10:
div {
background-color: limegreen;
max-height: 5em;
overflow-y: scroll;
}
<div>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br></div>
Like this:

But that Firefox refuses to render a lightgreen colored scroll bar:
div {
background-color: lightgreen;
max-height: 5em;
overflow-y: scroll;
}
<div>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br>Hi!<br></div>
See this:

What causes this behavior, and how can I predict it?
PS. Chrome 80 shows both scrollbars in the default style.
PS. There are questions on how to actively change scrollbar color in Firefox, but I’m not (right now) interested in pragmatic advice on “how to change scrollbar color“, but instead I’m asking and trying to understand when and why it happens automatically, and only for some background colors.
I’ve made an edit to your post, hoping to capture those who read a but too quick 🙂
Hah thx! That helps a lot. We posted edits at the same time – I’ve merged the two manually, and also slightly tweaked the TLDR.
I would say it’s a matter of contrast. try to play with the color picker and you will notice how the color is changing
I added some info on why I think it happens into the bottom with an edit – even with the scrollbar-color tag there are weird color problems, probably due to browser incompatibilites. Maybe it’s to do with light or dark colors? White is hard to see on lightgreen, but both dark and light text can be seen on limegreen.