{"id":20196821,"url":"https://github.com/itsjonq/stylis-plugin-css-variables","last_synced_at":"2025-04-10T10:44:39.474Z","repository":{"id":39625225,"uuid":"281544429","full_name":"ItsJonQ/stylis-plugin-css-variables","owner":"ItsJonQ","description":"🔄 Transforms CSS variable into static values for non-supported browsers","archived":false,"fork":false,"pushed_at":"2022-12-11T17:14:18.000Z","size":4501,"stargazers_count":8,"open_issues_count":21,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-31T01:04:46.393Z","etag":null,"topics":["css-in-js","css-variables","plugin","stylis","variables"],"latest_commit_sha":null,"homepage":"https://github.com/ItsJonQ/stylis-plugin-css-variables","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ItsJonQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-22T01:34:40.000Z","updated_at":"2021-08-06T16:41:44.000Z","dependencies_parsed_at":"2023-01-27T03:45:59.414Z","dependency_job_id":null,"html_url":"https://github.com/ItsJonQ/stylis-plugin-css-variables","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsJonQ%2Fstylis-plugin-css-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsJonQ%2Fstylis-plugin-css-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsJonQ%2Fstylis-plugin-css-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItsJonQ%2Fstylis-plugin-css-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ItsJonQ","download_url":"https://codeload.github.com/ItsJonQ/stylis-plugin-css-variables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248200773,"owners_count":21063975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-in-js","css-variables","plugin","stylis","variables"],"created_at":"2024-11-14T04:26:12.733Z","updated_at":"2025-04-10T10:44:39.455Z","avatar_url":"https://github.com/ItsJonQ.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# stylis-plugin-css-variables\n\n[![Build Status](https://travis-ci.org/ItsJonQ/stylis-plugin-css-variables.svg?branch=master)](https://travis-ci.org/ItsJonQ/stylis-plugin-css-variables)\n[![codecov](https://codecov.io/gh/ItsJonQ/stylis-plugin-css-variables/branch/master/graph/badge.svg)](https://codecov.io/gh/ItsJonQ/stylis-plugin-css-variables)\n[![npm version](https://badge.fury.io/js/stylis-plugin-css-variables.svg)](https://badge.fury.io/js/stylis-plugin-css-variables)\n\n\u003e Stylis plugin that transforms CSS variable into static values for non-supported browsers.\n\n## Table of contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n-   [Install](#install)\n-   [Usage](#usage)\n-   [How it works](#how-it-works)\n-   [Limitations](#limitations)\n-   [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Install\n\n```\nnpm install --save stylis-plugin-css-variables\n```\n\n## Usage\n\n```js\nimport Stylis from 'stylis';\nimport cssVariablesPlugin from 'stylis-plugin-css-variables';\n\nconst stylis = new Stylis();\nstylis.use(cssVariablesPlugin());\n\nconst rules = stylis(\n\t'',\n\t`.hello {\n        background: var(--bg, black);\n    }\n    `,\n);\n\nconsole.log(rules);\n// .hello {background:black;background: var(--bg, black);}\n```\n\n## How it works\n\nBy default, this plugin will only run in environments that **do not support CSS variables**. For the web, that typically means IE11 and below. It will not generate various for browsers like Chrome, Safari, or Firefix.\n\nIf you need this to always run, there is a `skipSupportedBrowsers` option that can be passed:\n\n```js\nstylis.use(cssVariablesPlugin({ skipSupportedBrowsers: false }));\n```\n\nThis plugin looks for any `var()` usage in the CSS declarations. If `var()` is found, it will attempt to retrieve the value from `:root`. If the CSS variable value is not available, it will attempt to use the provided fallback.\n\nIf a fallback is found, the static value will be prepended before the original CSS declaration:\n\n**Before**\n\n```css\n.hello {\n\tbackground: var(--bg, black);\n}\n```\n\n**After**\n\n```css\n.hello {\n\tbackground: black;\n\tbackground: var(--bg, black);\n}\n```\n\nHowever, if there are no `:root` values or fallbacks, then no static value will be generated.\n\nNested `var()` is supported!\n\n```css\n.hello {\n\tbackground: var(--bg, var(--black, var(--dark, black)));\n}\n```\n\n**After**\n\n```css\n.hello {\n\tbackground: black;\n\tbackground: var(--bg, var(--black, var(--dark, black)));\n}\n```\n\n## Limitations\n\nAutomatic variable value retrieval is limited only to the `:root` scope.\n\n## License\n\nMIT © [Q](https://jonquach.com) ✌️❤️\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsjonq%2Fstylis-plugin-css-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsjonq%2Fstylis-plugin-css-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsjonq%2Fstylis-plugin-css-variables/lists"}