I'd like to use a CSS variable to store a font in case the user doesn't have the specified font installed.
Example:
:root {
--common-font: Comic Sans MS;
}
.header1 {
font-family: CoolFont1, var(--common-font);
}
Will legacy browsers break if I add a reference to the variable in the font names?
https://caniuse.com/#feat=css-variables
Yes, it will break, you must use fallback font for legacy browser without using CSS variables.
For example:
.header {
font-family: sans-serif; /* This is fallback font for old browsers */
font-family: var(--common-font);
}
Also you can use a @supports condition with a dummy feature query:
.header {
@supports ( (--a: 0)) {
/* supported */
font-family: var(--common-font);
}
@supports ( not (--a: 0)) {
/* not supported */
font-family: sans-serif; /* This is fallback font for old browsers */
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With