5 Useful CSS functions using the new @function rule
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
CSS custom functions using the new @function rule have landed in Chrome 139, enabling developers to write reusable logic that accepts arguments and returns computed values. The article demonstrates five practical examples: a negation function for inverting values, an opacity function for creating transparent color variants, a fluid typography function that scales text responsively, a conditional border radius function that removes rounded corners near viewport edges, and a layout sidebar function for responsive grid layouts. These functions make CSS more organized and dynamic, similar to utility functions in JavaScript, and represent a significant step toward more powerful CSS capabilities with upcoming @mixin and @apply rules.
Table of contents
IntroductionNegation functionOpacity functionFluid typography functionConditionally rounded borderLayout sidebar functionBonus: light-dark theming functionWhat's next?The future is utils.css3 Comments
Sort: