# get-css-variables

> Import CSS variables into a JavaScript Object

Latest version **1.1.1** (published 2026-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-css-variables
pnpm add get-css-variables
yarn add get-css-variables
bun add get-css-variables
```

Provides the command `get-css-variables`.

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2026-02-26 |
| First published | 2020-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 20.0.0 |
| Dependencies | 0 |
| Unpacked size | 27.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1 |
| Author | Olof |
| Maintainers | oloff |
| Keywords | css |

## Links

- npm: https://www.npmjs.com/package/get-css-variables
- Repository: https://github.com/OlofFredriksson/get-css-variables
- Homepage: https://github.com/OlofFredriksson/get-css-variables#readme
- Issues: https://github.com/OlofFredriksson/get-css-variables/issues
- npm.io page: https://npm.io/package/get-css-variables

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2026-02-26
- 1.1.0 — 2025-11-05
- 1.0.0 — 2024-09-22
- 0.3.0 — 2021-01-09
- 0.2.0 — 2021-01-01
- 0.1.0 — 2020-10-07
- 0.0.3 — 2020-10-06

## README

# Get CSS variables

> Convert your CSS variables into a JavaScript Object

[![Build](https://github.com/OlofFredriksson/get-css-variables/workflows/Build/badge.svg)](https://github.com/OlofFredriksson/get-css-variables/actions)
[![npm](https://img.shields.io/npm/v/get-css-variables)](https://www.npmjs.com/package/get-css-variables)

## Run CLI via npx

`npx get-css-variables inputFile.css output.js`

## Usage

`npm install --save-dev get-css-variables`

### Node Api

Convert css variables into a JSON object:

#### ESM

```Javascript
import { getVariables } from "get-css-variables";

console.log(getVariables(":root { --dummy-color: blue }"));
```

#### CJS (Deprecated)

```Javascript
const { getVariables } = require("get-css-variables");

console.log(getVariables(":root { --dummy-color: blue }"));
```

### Output

```JSON
{ "--dummy-color": "blue" }
```

### CLI

Will create an output file containing a exported javascript module.

```
$ get-css-variables inputFile.css output.js
```

## Limits

- Only variables on the :root selector are supported.

## Development

```bash
$ npm install
$ npm run build
$ npm test
```

## Note

- Original code and credit to [Dashlane/css-variables-loader](https://github.com/Dashlane/css-variables-loader)
  Reason for this plugin was to remove Webpack depedency and add CLI tool.
- One use case for this plugin is together with [dvitamin/postcss-var-func-fallback](https://github.com/dvitamin/postcss-var-func-fallback).

---
_Source: https://npm.io/package/get-css-variables · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
