A UnoCSS preset that allows you to write CSS variables using classes.
- 🖊️ Write CSS variables without the need of complex selector or
style
attributes. - 📦 Easy Integration – Plug-and-play with any UnoCSS project.
- 🏗️ Attributify Mode support
pnpm i -D unocss-preset-css-var
// uno.config.ts
import { defineConfig } from 'unocss'
import { presetCssVar } from 'unocss-preset-css-var'
export default defineConfig({
presets: [
// ...
presetCssVar(),
],
})
You can open the Unocss Playground
If you are like me, you may have already created several style="--my-var:value
" in your project.
You can start using this preset to replace all those variables with the following workflow:
- Open VSCode with your project and open the search sidebar (
Ctrl/Command + Shift + F
). - Activate the regex. Use the
.*
symbol. - Search for
style="--(.+)"
. - Replace with
var:$1
. - Click 'Replace all'.