A card has color:black in a baseline rule. A later declaration uses color:if(supports(color:oklch(60% .2 30)):oklch(60% .2 30); else:tomato). That one declaration supplies either value. With @supports, a nested color:oklch(…) rule is included only when its condition is true; when false, the earlier black declaration remains. Inline else and cascade fallback are different mechanisms.
This lesson continues The Gold Standard of Websites, the Gold Standard of Education and the How X Works hub. Every condition, declaration, branch, cascade result and computed value is an original synthetic fixture. The lesson does not promise shipping support, replace feature detection with user-agent guessing or treat a true supports condition as proof of correct rendering.
Record condition syntax, substituted condition tokens, evaluated truth value, chosen branch, resulting token stream, declaration validity, included rule blocks, cascade inputs, computed value, browser build and unavailable behavior.
The CSS Values and Units Module Level 5 defines the proposed if() arbitrary substitution function and explicitly contrasts it with @media, @supports and @container rule gating. The CSS Conditional Rules Module Level 3 defines @supports. The CSS Conditional Values Module Level 1 tracks the conditional-value model. These are drafts; Values Level 5 is early exploration and may change substantially.
THE GOLD STANDARD · WEBSITES
if() selects a value inside one declaration; @supports decides whether a rule block participates in the cascade
The proposed CSS if() notation evaluates ordered supports(), media() or style() conditions and substitutes the first matching branch value. If no branch matches, it returns an empty token stream unless an else branch supplies a value. An @supports rule instead includes or excludes nested rules; when excluded, other declarations can still win through the cascade. These paths can yield the same pixels while having different fallback and invalidation behavior.
Fast route
Start with the decisive rule.
Start this route
Measurement route
Build the browser state and evidence ledger.
Start this route
Comparison route
Separate the nearest lookalikes.
Start this route
Transfer route
Change the context and retest.
Start this route
Reporting route
State limits and continue reading.
Start this route
Chapter contents
Open the full chapter index
- 1. Give the short scope rule
- 2. Read branch order
- 3. Use else as an explicit branch
- 4. Contrast cascade fallback
- 5. Separate supports syntax from rendering quality
- 6. Test media conditions inline
- 7. Test style conditions inline
- 8. Preserve substitution before condition parsing
- 9. Preserve substitution in the chosen value
- 10. Handle a destination-invalid chosen value
- 11. Keep rule specificity visible
- 12. Keep conditional scope visible
- 13. Use changed-context controls
- 14. Treat unsupported if() as unavailable
- 15. Avoid runtime-policy overclaims
- 16. Repair the pixel shortcut
- 17. Build a reproducible conditional ledger
- 18. Use conditional specifications and continue
1. Give the short scope rule
if() chooses a token stream within one declaration. @supports gates nested rules before the cascade determines a winner.
Original worked example. A color declaration chooses oklch or tomato inline, while an @supports block either contributes a declaration or contributes nothing. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Remove the inline else branch. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record branch selection and cascade participation separately. If this check fails, mark the claim unavailable and repair the method before continuing.
Keep grammar, substitution, evaluation, cascade and computed result in separate fields so matching pixels cannot rewrite the mechanism.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
2. Read branch order
if() evaluates ordered branches and returns the first true branch. It is not a merge of every true condition.
Original worked example. Two supports tests are true, so the earlier branch supplies the value. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Reverse the branches. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Save condition results and selected branch index. If this check fails, mark the claim unavailable and repair the method before continuing.
Use a positive case, a clean negative case and an unavailable case. Unavailable means the required syntax or evidence was not established.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
3. Use else as an explicit branch
The else keyword is always true and normally serves as the terminal branch. Without a match, the function returns an empty token stream.
Original worked example. if(media(width > 80rem):wide; else:narrow) always selects one label. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Remove else under a narrow viewport. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Inspect the resulting declaration validity. If this check fails, mark the claim unavailable and repair the method before continuing.
Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
4. Contrast cascade fallback
A false @supports condition removes its nested declarations from consideration, allowing earlier, lower-layer or less-specific declarations to win. if() does not rewind the cascade to an earlier declaration when no branch matches.
Original worked example. A baseline color survives a false @supports block. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Replace the block with a later if() declaration that returns empty. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Trace invalid-at-computed-value behavior and the final property value. If this check fails, mark the claim unavailable and repair the method before continuing.
Carry one plausible alternative through the ledger, then choose the next observation that separates it from the leading account.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
5. Separate supports syntax from rendering quality
Both supports() inside if() and @supports test CSS support conditions. A true result means the syntax is supported under the defined test, not that a component is usable or accessible.
Original worked example. The engine accepts a color syntax but the chosen contrast is poor. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Change only the background. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Keep grammar support and design checks independent. If this check fails, mark the claim unavailable and repair the method before continuing.
Name the relevant declaration, token stream, candidate, condition, random key, calculation or destination property.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
6. Test media conditions inline
The draft lets if() test media conditions and select a value without duplicating an entire rule. @media instead gates rule blocks.
Original worked example. Padding chooses 1rem or 2rem from an inline width condition. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Move the same choice into two @media rules. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Compare cascade, source order and computed values. If this check fails, mark the claim unavailable and repair the method before continuing.
Archive source, fixture, rules, computed styles, browser version and raw exceptions so another reader can reproduce the conclusion.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
7. Test style conditions inline
A style() test can inspect a style query, but cycles involving the property replacement context evaluate false under the draft.
Original worked example. –result references a condition on itself and takes the else branch. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Move the queried custom property to an ancestor. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Log query source and cyclic-context decision. If this check fails, mark the claim unavailable and repair the method before continuing.
Keep grammar, substitution, evaluation, cascade and computed result in separate fields so matching pixels cannot rewrite the mechanism.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
8. Preserve substitution before condition parsing
if() is an arbitrary substitution function. Substitutions in its condition are performed before parsing the condition, and an unparseable branch condition is skipped.
Original worked example. A custom property supplies a valid media threshold. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Change it to unmatched punctuation. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Save raw and substituted condition tokens. If this check fails, mark the claim unavailable and repair the method before continuing.
Use a positive case, a clean negative case and an unavailable case. Unavailable means the required syntax or evidence was not established.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
9. Preserve substitution in the chosen value
Only after a condition succeeds is the corresponding value substituted and returned. Unchosen value branches should not be treated as computed results.
Original worked example. The true branch contains var(–tone), while a later branch contains an invalid reference. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Flip the condition. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record which branch value was substituted. If this check fails, mark the claim unavailable and repair the method before continuing.
Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
10. Handle a destination-invalid chosen value
Choosing a branch does not guarantee that its tokens satisfy the destination property grammar. A selected invalid value can invalidate the declaration.
Original worked example. width:if(else:red) selects red and fails as width. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Change red to 2rem. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Separate condition truth from destination parsing. If this check fails, mark the claim unavailable and repair the method before continuing.
Carry one plausible alternative through the ledger, then choose the next observation that separates it from the leading account.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
11. Keep rule specificity visible
@supports does not change selector specificity. The nested rule enters the cascade with its selector, origin, layer, importance and source order.
Original worked example. A supported nested rule still loses to a more specific declaration. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Raise only the selector specificity. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Compute support first and cascade second. If this check fails, mark the claim unavailable and repair the method before continuing.
Name the relevant declaration, token stream, candidate, condition, random key, calculation or destination property.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
12. Keep conditional scope visible
@supports can gate multiple rules and declarations; if() affects the one value position in which it appears. Choosing between them changes maintenance and cascade structure.
Original worked example. One supports block enables a layout bundle. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Replace one property with if() and leave the others gated. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. List which declarations participate in each design. If this check fails, mark the claim unavailable and repair the method before continuing.
Archive source, fixture, rules, computed styles, browser version and raw exceptions so another reader can reproduce the conclusion.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
13. Use changed-context controls
Change one of condition truth, branch order, selector specificity, layer order or destination grammar at a time.
Original worked example. A four-row matrix isolates each failure stage. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Repeat with a media condition instead of supports. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Predict the first changed stage before loading the page. If this check fails, mark the claim unavailable and repair the method before continuing.
Keep grammar, substitution, evaluation, cascade and computed result in separate fields so matching pixels cannot rewrite the mechanism.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
14. Treat unsupported if() as unavailable
A browser that drops the proposed notation has not evaluated its conditions. A baseline declaration or rule-gated pattern must preserve essential styling.
Original worked example. The engine keeps color:black and drops a later if() declaration. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Run an @supports-based alternative. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Record parser acceptance and computed style. If this check fails, mark the claim unavailable and repair the method before continuing.
Use a positive case, a clean negative case and an unavailable case. Unavailable means the required syntax or evidence was not established.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
15. Avoid runtime-policy overclaims
CSS conditions do not grant permissions, fetch resources or prove application state. They must not be used as security or authorization decisions.
Original worked example. A style branch cannot establish that a user may view private content. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Change the condition to a media preference. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Keep presentation choice and application policy separate. If this check fails, mark the claim unavailable and repair the method before continuing.
Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
16. Repair the pixel shortcut
Identical final pixels can arise from inline branch selection, a gated rule, an earlier cascade winner or an invalid declaration falling back to initial or inherited behavior.
Original worked example. Four fixtures all render tomato text through different paths. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Inspect matched rules and computed styles. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Require mechanism evidence beside screenshots. If this check fails, mark the claim unavailable and repair the method before continuing.
Carry one plausible alternative through the ledger, then choose the next observation that separates it from the leading account.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
17. Build a reproducible conditional ledger
Preserve every condition, substitution, truth value, chosen branch, block inclusion, matched declaration, cascade result and computed value.
Original worked example. The matrix includes true, false, unparseable, cyclic and unsupported cases. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. Repeat after changing the custom property at runtime. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Version drafts and browser builds. If this check fails, mark the claim unavailable and repair the method before continuing.
Name the relevant declaration, token stream, candidate, condition, random key, calculation or destination property.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Previous chapter · Contents · Next chapter
18. Use conditional specifications and continue
Values Level 5 owns inline value choice; Conditional Rules owns @supports gating; nearby articles own style queries, substitution and invalid values.
Original worked example. The route follows condition parsing, truth, value or rule participation, cascade and computation. The declarations, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.
Changed-context transfer. When grammar changes, rerun every positive and negative control. State what changed, predict the consequence and revise only the conclusion that depended on that condition.
Practical evidence check. Save source URLs, access date and raw rule traces. If this check fails, mark the claim unavailable and repair the method before continuing.
Archive source, fixture, rules, computed styles, browser version and raw exceptions so another reader can reproduce the conclusion.
Before closing, reconcile the original fixture against the chapter rule: identify the declaration, token stream, condition, calculation or destination grammar and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, stylesheet or document state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.
Grouped reading routes
Core route
Companion lessons
- Separating first-valid() Candidate Parsing from var() Token Fallback
- Separating random() Numeric Sampling from random-item() Discrete Choice
- Separating progress() Normalization from calc() Arithmetic
Related specialist lessons
Sources and further study
CSS Values and Units Module Level 5. Used for the standard definitions, material mechanisms or method limits developed in this lesson.
CSS Conditional Rules Module Level 3. Used for the standard definitions, material mechanisms or method limits developed in this lesson.
CSS Conditional Values Module Level 1. Used for the standard definitions, material mechanisms or method limits developed in this lesson.
The worked examples and transfer checks are developed here and state their own assumptions. The linked sources support the underlying CSS parsing, substitution, evaluation and cascade principles.
Return to contents · Return to The Gold Standard of Websites