2 years ago

#54307

test-img

Maverick Fabroa

css selector and @media rule in a single declaration

I have a css file that has dark mode theme. My css file is something like this:

html.dark {
    /* Dark mode properties */
}

@media (prefers-color-scheme: dark) {
    /* Dark mode properties */
}

Since they have the same dark mode properties; it's better to use a single dark mode properties for both of them to decrease the css file size and increase page load.

Is there a way to do a selector and a @media rule in a single declaration something like this?:

html.dark, @media (prefers-color-scheme: dark) {
    /* Dark mode properties */
}

css

css-selectors

darkmode

0 Answers

Your Answer

Accepted video resources