Wednesday, January 14, 2026

Taking part in With CodePen slideVars | CSS-Tips


Tremendous cool new CodePen function alert! You’ve in all probability seen a bunch of “interactive” demos that allow you to modified values on the fly from a UI panel embedded instantly within the demo. Jhey’s demos come instantly to thoughts, like this one:

That’s a device referred to as TweakPane doing the work. There’s one other one referred to as Knobs by Yair Even Or that Adam Argyle usually makes use of:

I’ve usually faked it with both the Checkbox Hack or a sprinkle of JavaScript once I’m demoing a really particular idea:

OK, sufficient examples as a result of CodePen has a homegrown device of its personal referred to as slideVars. All you must do is import it and name it within the JavaScript panel:

import { slideVars } from "@codepen/slidevars";

slideVars.init();

You may import it right into a venture off CodePen should you’re so inclined.

That two-liner does a number of lifting. It auto-detects CSS variables in your CSS and builds the panel for you, absolutely-positioned within the top-right nook:

It appears like you must declare your variables on the :root aspect with default utilization. I attempted scoping them on to the aspect and it was a no-go. It’s attainable with a handbook configuration, although.

Fairly cool, proper? You may manually configure the enter sort, a price vary, a default worth, unit sort, and sure, a scope that targets the aspect the place the variables are outlined. So far as models go, it helps all types of CSS numeric models. That features unit-less values, although the documentation doesn’t explicitly say it. Simply go away the unit property as an empty string ("").

I suppose the one factor I’d like is to inform slideVars precisely what increments to make use of when manually configuring issues. For instance, unit-less values merely increment in integers, even should you outline the default worth as a decimal:

It really works in default mode, nevertheless:

There’s a approach to place the slideVars wherever you need by slapping a customized aspect the place you need it within the HTML. It’s auto-placed on the backside of the HTML by default.


  

Customized Label!

Or CSS it by choosing the customized aspect:

A lot enjoyable!

Related Articles

Latest Articles