Interpolating Numeric CSS Variables

We can make variables in CSS pretty easily:

:root {
  --scale: 1;
}

And we can declare them on any element:

.thing {
  transform: scale(--scale);
}

Even better for an example like this is applying the variable on a user …


Interpolating Numeric CSS Variables originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

https://css-tricks.com/interpolating-numeric-css-variables/

Creată 3y | 30 aug. 2022, 14:20:46


Autentifică-te pentru a adăuga comentarii

Alte posturi din acest grup

What I Took From the State of Dev 2025 Survey

State of Devs 2025 survey results are out! Sunkanmi Fafowora highlights a few key results about diversity, health, and salaries.


16 iul. 2025, 14:40:23 | CSS tricks
Setting Line Length in CSS (and Fitting Text to a Container)

The many ways to juggle line length when working with text... including two proposed properties that could make it easier in the future.


14 iul. 2025, 14:10:12 | CSS tricks
The Layout Maestro Course

Layout. It’s one of those easy-to-learn, difficult-to-master things, like they say about playing bass. Not because it’s innately difficult to, say, place two elements next to each other

11 iul. 2025, 18:50:13 | CSS tricks
Scroll-Driven Sticky Heading

I was playing around with scroll-driven animations, just searching for all sorts of random things you could do. That’s when I came up with the idea to animate main headings and, using scroll-driven

11 iul. 2025, 14:20:16 | CSS tricks
Better CSS Shapes Using shape() — Part 4: Close and Move

This is the fourth post in a series about the new CSS shape() function. So far, we’ve covered the most common commands y

7 iul. 2025, 12:50:19 | CSS tricks
The Gap Strikes Back: Now Stylable

Styling the space between layout items — the gap — has typically required some clever workarounds. But a new CSS feature changes all that with just a few simple CSS properties that make it easy, ye

1 iul. 2025, 13:20:09 | CSS tricks
Using CSS Cascade Layers With Tailwind Utilities

Being the bad boy I am, I don't take Tailwind's default approach to cascade layers as the "best" one. Over a year experimenting with Tailwind and vanilla CSS, I've come across what I believe is a b

30 iun. 2025, 14:10:12 | CSS tricks