CSS conditionals with the new if() function | Blog | Chrome for Developers
Briefly

The CSS if() function, introduced in Chrome 137, allows for inline conditionals in styles, leading to cleaner and more efficient design. This function employs a series of condition-value pairs and supports an else statement for cases where no conditions are met. Key applications include inline media queries, enabling developers to tailor styles based on user preferences and device characteristics directly within the CSS. Examples demonstrate how button sizes change based on pointer type, emphasizing usability. Additionally, if() facilitates inline support queries, detecting features like wide-gamut color support.
The CSS if() function simplifies dynamic styles by allowing condition-value pairs that apply styles immediately to an element, enhancing the developer interface for styles like media queries.
With the if() function, developers can create inline media queries, checking for user preferences or viewport conditions without duplicating styling logic across different locations in the code.
Using if() allows immediate application of styles to elements, leveraging conditions such as pointer type to adjust button sizes for better usability and accessibility based on user device capabilities.
Support queries can be constructed with if() to offer feature detection, such as checking for wide-gamut color support, and applying additional styles or content conditionally based on that support.
Read at Chrome for Developers
[
|
]