@@ -2657,15 +2657,86 @@ Appendix A: Arbitrary Substitution Functions</h2>
26572657 If a property value contains one or more [=arbitrary substitution functions=] ,
26582658 and those functions are themselves syntactically valid,
26592659 the entire value's grammar must be assumed to be valid at parse time.
2660- It is only syntax-checked at computed-value time,
2661- after [=arbitrary substitution=] .
26622660
26632661 <wpt pathprefix="css/css-variables">
26642662 variable-reference-18.html
26652663 variable-reference-19.html
26662664 variable-reference-30.html
26672665 </wpt>
26682666
2667+ [=Arbitrary substitution functions=] are [=substituted=]
2668+ during style [=computed value|computation=] ,
2669+ before any other value transformations or introspection can occur.
2670+ If a property,
2671+ after [=substitution=] ,
2672+ does not match its declared grammar,
2673+ the declaration is [=invalid at computed-value time=] .
2674+
2675+ <wpt pathprefix="css/css-variables">
2676+ variable-declaration-16.html
2677+ variable-declaration-17.html
2678+ variable-declaration-18.html
2679+ variable-declaration-19.html
2680+ variable-declaration-21.html
2681+ variable-transitions-transition-property-all-before-value.html
2682+ variable-transitions-value-before-transition-property-all.html
2683+ </wpt>
2684+
2685+ If a property value,
2686+ after [=substitution=] ,
2687+ contains only a single [=CSS-wide keyword=]
2688+ (and possibly whitespace/comments),
2689+ its value is determined as if that keyword were its [=specified value=] all along.
2690+
2691+ <wpt pathprefix="css/css-variables">
2692+ whitespace-in-fallback-crash.html
2693+ wide-keyword-fallback-001.html
2694+ wide-keyword-fallback-002.html
2695+ </wpt>
2696+
2697+ <div class='example'>
2698+ For example,
2699+ the following usage is fine from a syntax standpoint,
2700+ but results in nonsense when the variable is substituted in:
2701+
2702+ <pre>
2703+ :root { --looks-valid: 20px; }
2704+ p { background-color: var(--looks-valid); }
2705+ </pre>
2706+
2707+ Since ''20px'' is an invalid value for 'background-color' ,
2708+ the property becomes [=invalid at computed-value time=] ,
2709+ and instead resolves to ''transparent''
2710+ (the [=initial value=] for 'background-color' ).
2711+
2712+ If the property was one that's inherited by default,
2713+ such as 'color!!property' ,
2714+ it would compute to the inherited value
2715+ rather than the initial value.
2716+ </div>
2717+
2718+ <div class='example'>
2719+ While a ''var()'' function can't get a [=CSS-wide keyword=]
2720+ from the [=custom property=] itself--
2721+ if you tried to specify that,
2722+ like ''--foo: initial;'' ,
2723+ it would just trigger [[css-cascade-4#defaulting-keywords|explicit defaulting]]
2724+ for the custom property--
2725+ it can have a [=CSS-wide keyword=] in its fallback:
2726+
2727+ <pre>
2728+ p { color: var(--does-not-exist, initial); }
2729+ </pre>
2730+
2731+ In the above code, if the ''--does-not-exist'' property didn't exist
2732+ or is [=invalid at computed-value time=] ,
2733+ the ''var()'' will instead substitute in the ''initial'' keyword,
2734+ making the property behave as if it was originally ''color: initial'' .
2735+ This will make it take on the document's initial 'color' value,
2736+ rather than defaulting to inheritance,
2737+ as it would if there were no fallback.
2738+ </div>
2739+
26692740 Each [=arbitrary substitution function=]
26702741 must define how to <dfn export>resolve an arbitrary substitution function</dfn>
26712742 for itself,
@@ -2796,79 +2867,6 @@ Appendix A: Arbitrary Substitution Functions</h2>
27962867 variable-reference-without-whitespace.html
27972868 </wpt>
27982869
2799- [=Arbitrary substitution functions=] are [=substituted=]
2800- during style [=computed value|computation=] ,
2801- before any other value transformations or introspection can occur.
2802- If a property,
2803- after [=substitution=] ,
2804- does not match its declared grammar,
2805- the declaration is <a>invalid at computed-value time</a> .
2806-
2807- <wpt pathprefix="css/css-variables">
2808- variable-declaration-16.html
2809- variable-declaration-17.html
2810- variable-declaration-18.html
2811- variable-declaration-19.html
2812- variable-declaration-21.html
2813- variable-transitions-transition-property-all-before-value.html
2814- variable-transitions-value-before-transition-property-all.html
2815- </wpt>
2816-
2817- If a property,
2818- after [=substitution=] ,
2819- contains only a [=CSS-wide keyword=]
2820- (and possibly whitespace/comments),
2821- its value is determined as if that keyword were its [=specified value=] all along.
2822-
2823- <wpt pathprefix="css/css-variables">
2824- whitespace-in-fallback-crash.html
2825- wide-keyword-fallback-001.html
2826- wide-keyword-fallback-002.html
2827- </wpt>
2828-
2829- <div class='example'>
2830- For example,
2831- the following usage is fine from a syntax standpoint,
2832- but results in nonsense when the variable is substituted in:
2833-
2834- <pre>
2835- :root { --looks-valid: 20px; }
2836- p { background-color: var(--looks-valid); }
2837- </pre>
2838-
2839- Since ''20px'' is an invalid value for 'background-color' ,
2840- the property becomes [=invalid at computed-value time=] ,
2841- and instead resolves to ''transparent''
2842- (the [=initial value=] for 'background-color' ).
2843-
2844- If the property was one that's inherited by default,
2845- such as 'color!!property' ,
2846- it would compute to the inherited value
2847- rather than the initial value.
2848- </div>
2849-
2850- <div class='example'>
2851- While a ''var()'' function can't get a [=CSS-wide keyword=]
2852- from the [=custom property=] itself--
2853- if you tried to specify that,
2854- like ''--foo: initial;'' ,
2855- it would just trigger [[css-cascade-4#defaulting-keywords|explicit defaulting]]
2856- for the custom property--
2857- it can have a [=CSS-wide keyword=] in its fallback:
2858-
2859- <pre>
2860- p { color: var(--does-not-exist, initial); }
2861- </pre>
2862-
2863- In the above code, if the ''--does-not-exist'' property didn't exist
2864- or is [=invalid at computed-value time=] ,
2865- the ''var()'' will instead substitute in the ''initial'' keyword,
2866- making the property behave as if it was originally ''color: initial'' .
2867- This will make it take on the document's initial 'color' value,
2868- rather than defaulting to inheritance,
2869- as it would if there were no fallback.
2870- </div>
2871-
28722870<!-- Big Text: invalid
28732871
28742872████ █ █▌ █▌ █▌ ███▌ █▌ ████ ████▌
0 commit comments