My website consists of static html pages, mainly just semantic HTML. There are several style sheets, which I swap out as I change the look of the website (so older pages keep the old look, generally).
On top of that, I like to style individual pages depending on the contents. For example, set a different background or text colour. Like this DOS Gaming article with a retro theme.
I’m now moving towards better support for dark/light mode, and I find that these CSS overwrites often break things. I usually like to just apply theming to the light mode, and leave the dark mode to whatever the browser defaults are.
So for this example, I want to set the text colour of headings to red if the user is using light mode only.
The reference page is online here, which uses my latest style sheet I’m working on. For dark/light there is just:
html {
color-scheme: light;}
@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;}
}
I understand how to use the light-dark() function, but is it possible to just set the "light’ only?
Secondly - how can I target this on one page only? Currently I would just put some inline CSS on the heading tags, which is cumbersome. But the only way I know other than a page specific style sheet.
I’ve noticed it’s possible to use the CSS variable names from your stylesheet in the inline page CSS, but this feels, off? Is that bad practice? What if the variable gets renamed? It feels like a bad idea.
Actually, maybe using tags works here as long as there is never any specific colour declared in the main css file? Or hyper specific targeting with classes or something?
Any elegant ways to handle this!? Any and all thoughts appreciated.