Playing With CodePen slideVars

Super cool new CodePen feature alert! You’ve probably seen a bunch of “interactive” demos that let you changed values on the fly from a UI panel embedded directly in the demo.


Playing With CodePen slideVars originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham

Super cool new CodePen feature alert! You’ve probably seen a bunch of “interactive” demos that let you changed values on the fly from a UI panel embedded directly in the demo. Jhey’s demos come immediately to mind, like this one:

That’s a tool called TweakPane doing the work. There’s another one called Knobs by Yair Even Or that Adam Argyle often uses:

I’ve often faked it with either the Checkbox Hack or a sprinkle of JavaScript when I’m demoing a very specific concept:

OK, enough examples because CodePen has a homegrown tool of its own called slideVars. All you have to do is import it and call it in the JavaScript panel:

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

slideVars.init();

You can import it into a project off CodePen if you’re so inclined.

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

It looks like you have to declare your variables on the :root element with default usage. I tried scoping them directly to the element and it was a no-go. It’s possible with a manual configuration, though.

Pretty cool, right? You can manually configure the input type, a value range, a default value, unit type, and yes, a scope that targets the element where the variables are defined. As far as units go, it supports all kinds of CSS numeric units. That includes unit-less values, though the documentation doesn’t explicitly say it. Just leave the unit property as an empty string ("").

I guess the only thing I’d like is to tell slideVars exactly what increments to use when manually configuring things. For example, unit-less values simply increment in integers, even if you define the default value as a decimal:

It works in default mode, however:

There’s a way to place the slideVars wherever you want by slapping a custom element where you want it in the HTML. It’s auto-placed at the bottom of the HTML <body> by default.

<slide-vars>
  <p>Custom Label!</p>
</slide-vars>

Or CSS it by selecting the custom element:

So much fun!


Playing With CodePen slideVars originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Geoff Graham


Print Share Comment Cite Upload Translate Updates
APA

Geoff Graham | Sciencx (2026-01-14T14:59:07+00:00) Playing With CodePen slideVars. Retrieved from https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/

MLA
" » Playing With CodePen slideVars." Geoff Graham | Sciencx - Wednesday January 14, 2026, https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/
HARVARD
Geoff Graham | Sciencx Wednesday January 14, 2026 » Playing With CodePen slideVars., viewed ,<https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/>
VANCOUVER
Geoff Graham | Sciencx - » Playing With CodePen slideVars. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/
CHICAGO
" » Playing With CodePen slideVars." Geoff Graham | Sciencx - Accessed . https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/
IEEE
" » Playing With CodePen slideVars." Geoff Graham | Sciencx [Online]. Available: https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/. [Accessed: ]
rf:citation
» Playing With CodePen slideVars | Geoff Graham | Sciencx | https://www.scien.cx/2026/01/14/playing-with-codepen-slidevars/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.