Definitely, it will break in legacy browser. However I think one can use postcss-css-variables
plugin to do the conversion. So that you can keep on using the CSS variable feature, but do not need to worry too much on legacy browser. When those legacy browsers fades out, you can just remove the plugin.
Checkout https://www.npmjs.com/package/postcss-css-variables for details.
It also has a playground, which you can play around to see how it behaves.
For example,
:root {
--color-background: #ffaaaa;
--font-color: #2222ff;
}
@media (prefers-color-scheme: dark) {
:root {
--color-background: #aaaaff;
--font-color: #ffFF22;
}
}
body {
background-color: var(--color-background);
}
p {
color: var(--font-color);
}
will be convert to
body {
background-color: #ffaaaa;
}
@media (prefers-color-scheme: dark) {
body {
background-color: #aaaaff;
}
}
p {
color: #2222ff;
}
@media (prefers-color-scheme: dark) {
p {
color: #ffFF22;
}
}