CKTIS / CSS
if() — conditional value selection
`if()` selects the value belonging to the first true branch in an ordered semicolon-separated list.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
if( [ <if-branch> ; ]* <if-branch> ;? )if() selects the value belonging to the first true branch in an ordered semicolon-separated list.
if(supports(display: grid): 80px; else: 20px) yields 80px; if(supports(display: cktis): 90px; else: 30px) selects 30px. With no matching branch, if(supports(display: cktis): 25px) leaves the element at 200px, not the earlier 15px; the syntax test returns true.
Grammar: if( [ <if-branch> ; ]* <if-branch> ;? ).
Conditions can be supports(), media(), and style(), while else is always true. No match returns an empty token stream and does not roll the cascade back to an older declaration, so a fallback must be inside the function. CSS Values 5 defines the current semicolon-separated condition:value syntax; CSS Conditional Values 1 is a not-ready unofficial proposal with a conflicting older comma sketch.
Examples
const host=document.createElement('div');host.style.width='200px';document.body.append(host);
const truth=document.createElement('div');truth.style.width='if(supports(display: grid): 80px; else: 20px)';
const fallback=document.createElement('div');fallback.style.height='if(supports(display: cktis): 90px; else: 30px)';
const noMatch=document.createElement('div');noMatch.style.cssText='width:15px;width:if(supports(display: cktis): 25px)';
host.append(truth,fallback,noMatch);
console.log('true-branch='+getComputedStyle(truth).width+'; else-branch='+getComputedStyle(fallback).height+'; no-match='+getComputedStyle(noMatch).width+'; syntax-supported='+CSS.supports('width','if(supports(display: grid): 1px; else: 2px)'));Result
true-branch=80px; else-branch=30px; no-match=200px; syntax-supported=true
`if()` selects the value belonging to the first true branch in an ordered semicolon-separated list.