The following CSS code will generate different results depending on whether or not variable --test2 is defined:
html::before {
content: "test1:" var(--test1) " test2:" var(--test2);
}
If --test1 and --test2 are defined, the test content will be displayed within the viewport. If --test1 is defined but --test2 is not defined, none of the test content is displayed.
Is this the correct behavior, and if so, why?
From the specification:
In your case, you didn't define the variable so it has
initialas value which will makecontentfallback to its initial value too (which isnone) so nothing will show.From the same Specification:
So better consider a fallback: