Skip to main content

Harshal V. LADHE

The CSS if() Function

Using the CSS `if()` function to choose property values inline based on media, support, or style queries.

Content tagged if-function

  • Tutorial:Conditional CSS Values with the if() Function

    Swap CSS values by media, supports, or style conditions.
    The if() function picks between several values inside one CSS declaration based on a media(), supports(), or style() condition — collapsing what used to require duplicating an entire rule under @media/@supports, or a JS class toggle, into one line, with a fallback for browsers that don't support it yet.
    Published at:
    Categories:CSS
    Estimated reading time:5 min read