function
If() — CSS reference
Selects a CSS value by testing conditions in order. The style() condition can inspect a custom property on the element; else is an unconditional final branch. This is a value function, not a selector or a rule block. A previous ordinary declaration provides fallback for browsers that reject the syntax.
Formal Syntax & Structure
css syntaxcss
color: if(style(--theme: dark): white; else: black);Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>if()</title><style>body{margin:16px;font:16px/1.5 system-ui;background:white;color:#172033} .demo{background:#dbeafe;box-sizing:border-box} button,select{font:inherit}#a{--theme:dark;color:black;color:if(style(--theme: dark):white;else:black);background:#172033}</style><body><div id="a" class="demo">Content</div></body></html>