Hi there,
I’m using the Casper theme (v 5.11.1) with automatic switching between light and dark modes for accessibility.
The problem I’m encountering is that when selecting text in posts, the highlighting color is the same for both light and dark mode, which means that the dark mode selected text cannot be read because it doesn’t contrast well with the highlight color. (see images).
I tried changing ::selection background color in the global.css file, but that broke the whole theme.
Is there any way to change the selection color on the text body for Casper? alternatively, how do I get it to have a different selection color in dark and light modes for better visibility?
Thanks!
You dont need to edit global.css for this (Casper serves a built css file, so editing the source file directly is what tends to break things). Paste this into Settings → Code injection → Site header instead:
<style>
::selection { background: #daf2fd; color: #15171a; }
html.dark-mode ::selection { background: #3b5bdb; color: #fff; }
@media (prefers-color-scheme: dark) {
html.auto-color ::selection { background: #3b5bdb; color: #fff; }
}
</style>
The first line keeps the light mode highlight but forces dark text, so selected text is always readable. The other two cover dark mode, both when the theme is set to Dark and when it’s on Auto and the visitor’s device is in dark mode. Swap the colours for whatever fits your site.