Can a recursive variable be expressed in css?

You can use two CSS variables to simulate the recursive behavior and avoid cycle dependency. Here is an example: body { –x: 10; } .y { –y: calc(var(–x) + 1); } .x{ –x: calc(var(–y) + 1); } .result { border-right:calc(1px * var(–y)) solid red; border-left:calc(1px * var(–x)) solid green; height:50px; } <body> <div class=”y”> <div … Read more

CSS animate custom properties/variables

This can be achieved by defining variables using (as of writing this, not well-supported) @property, which allows declaring types and that allows the browser to “understand”, for example, that a certain property (variable) is a Number and then it can gradually animate/transition that variable. Example Code: @property –opacity { syntax: ‘<number>’; /* <- defined as … Read more

Avoiding repeated constants in CSS

Recently, variables have been added to the official CSS specs. Variables allow you to so something like this : body, html { margin: 0; height: 100%; } .theme-default { –page-background-color: #cec; –page-color: #333; –button-border-width: 1px; –button-border-color: #333; –button-background-color: #f55; –button-color: #fff; –gutter-width: 1em; float: left; height: 100%; width: 100%; background-color: var(–page-background-color); color: var(–page-color); } button … Read more

how to reset a CSS variable (aka custom properties) and use the fallback one?

You can unset the value using initial to use the fallback one: :root { –border-width-top: 2px; –border-width-right: 2px; –border-width-bottom: 2px; –border-width-left: 2px; –border-width: 0; } div { margin:5px; border-color: red; border-style: solid; border-width: var(–border-width, var(–border-width-top) var(–border-width-right) var(–border-width-bottom) var(–border-width-left)); } div.box { –border-width:initial; –border-width-top: 10px; } <div>some content</div> <div class=”box”>some content</div> from the the specification: The … Read more

Why can’t I animate custom properties (aka CSS variables)?

When this question was asked, it wasn’t possible to animate custom properties, as @temani afif correctly pointed out – since the UA has no way to interpret their contents Since then, CSS Houdini have put together the CSS Properties and Values API specification This specification extends [css-variables], allowing the registration of properties that have a … Read more