{"id":13440900,"url":"https://github.com/postcss/postcss-custom-properties","last_synced_at":"2025-10-01T06:32:06.862Z","repository":{"id":19139094,"uuid":"22369106","full_name":"postcss/postcss-custom-properties","owner":"postcss","description":"Use Custom Properties in CSS","archived":true,"fork":false,"pushed_at":"2022-02-18T13:02:35.000Z","size":552,"stargazers_count":596,"open_issues_count":43,"forks_count":77,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-10-29T14:46:09.753Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://postcss.github.io/postcss-custom-properties","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/postcss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-29T05:48:21.000Z","updated_at":"2024-08-12T10:47:04.000Z","dependencies_parsed_at":"2022-08-01T02:48:50.008Z","dependency_job_id":null,"html_url":"https://github.com/postcss/postcss-custom-properties","commit_stats":null,"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-custom-properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-custom-properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-custom-properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/postcss%2Fpostcss-custom-properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/postcss","download_url":"https://codeload.github.com/postcss/postcss-custom-properties/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234837142,"owners_count":18894544,"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":[],"created_at":"2024-07-31T03:01:27.666Z","updated_at":"2025-10-01T06:32:06.565Z","avatar_url":"https://github.com/postcss.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e⚠️ PostCSS Color Custom Properties was moved to \u003ca href=\"https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-custom-properties\"\u003e@csstools/postcss-plugins\u003c/a\u003e. ⚠️ \u003cbr\u003e\n\u003ca href=\"https://github.com/csstools/postcss-plugins/discussions/75\"\u003eRead the announcement\u003c/a\u003e\u003c/div\u003e\n\n# PostCSS Custom Properties [\u003cimg src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"PostCSS\" width=\"90\" height=\"90\" align=\"right\"\u003e][postcss]\n\n[![NPM Version][npm-img]][npm-url]\n[![CSS Standard Status][css-img]][css-url]\n[![Build Status][cli-img]][cli-url]\n[![Support Chat][git-img]][git-url]\n\n[PostCSS Custom Properties] lets you use Custom Properties in CSS, following\nthe [CSS Custom Properties] specification.\n\n[!['Can I use' table](https://caniuse.bitsofco.de/image/css-variables.png)](https://caniuse.com/#feat=css-variables)\n\n```pcss\n:root {\n  --color: red;\n}\n\nh1 {\n  color: var(--color);\n}\n\n/* becomes */\n\n:root {\n  --color: red;\n}\n\nh1 {\n  color: red;\n  color: var(--color);\n}\n```\n\n**Note:** This plugin only processes variables that are defined in the `:root` selector.\n\n## Usage\n\nAdd [PostCSS Custom Properties] to your project:\n\n```bash\nnpm install postcss-custom-properties --save-dev\n```\n\nUse [PostCSS Custom Properties] to process your CSS:\n\n```js\nconst postcssCustomProperties = require('postcss-custom-properties');\n\npostcssCustomProperties.process(YOUR_CSS /*, processOptions, pluginOptions */);\n```\n\nOr use it as a [PostCSS] plugin:\n\n```js\nconst postcss = require('postcss');\nconst postcssCustomProperties = require('postcss-custom-properties');\n\npostcss([\n  postcssCustomProperties(/* pluginOptions */)\n]).process(YOUR_CSS /*, processOptions */);\n```\n\n[PostCSS Custom Properties] runs in all Node environments, with special instructions for:\n\n| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |\n| --- | --- | --- | --- | --- | --- |\n\n## Options\n\n### preserve\n\nThe `preserve` option determines whether Custom Properties and properties using\ncustom properties should be preserved in their original form. By default, both\nof these are preserved.\n\n```js\npostcssCustomProperties({\n  preserve: false\n});\n```\n\n```pcss\n:root {\n  --color: red;\n}\n\nh1 {\n  color: var(--color);\n}\n\n/* becomes */\n\nh1 {\n  color: red;\n}\n```\n\n### importFrom\n\nThe `importFrom` option specifies sources where Custom Properties can be imported\nfrom, which might be CSS, JS, and JSON files, functions, and directly passed\nobjects.\n\n```js\npostcssCustomProperties({\n  importFrom: 'path/to/file.css' // =\u003e :root { --color: red }\n});\n```\n\n```pcss\nh1 {\n  color: var(--color);\n}\n\n/* becomes */\n\nh1 {\n  color: red;\n}\n```\n\nMultiple sources can be passed into this option, and they will be parsed in the\norder they are received. JavaScript files, JSON files, functions, and objects\nwill need to namespace Custom Properties using the `customProperties` or\n`custom-properties` key.\n\n```js\npostcssCustomProperties({\n  importFrom: [\n    'path/to/file.css',   // :root { --color: red; }\n    'and/then/this.js',   // module.exports = { customProperties: { '--color': 'red' } }\n    'and/then/that.json', // { \"custom-properties\": { \"--color\": \"red\" } }\n    {\n      customProperties: { '--color': 'red' }\n    },\n    () =\u003e {\n      const customProperties = { '--color': 'red' };\n\n      return { customProperties };\n    }\n  ]\n});\n```\n\nSee example imports written in [CSS](test/import-properties.css),\n[JS](test/import-properties.js), and [JSON](test/import-properties.json).\n\n### exportTo\n\nThe `exportTo` option specifies destinations where Custom Properties can be exported\nto, which might be CSS, JS, and JSON files, functions, and directly passed\nobjects.\n\n```js\npostcssCustomProperties({\n  exportTo: 'path/to/file.css' // :root { --color: red; }\n});\n```\n\nMultiple destinations can be passed into this option, and they will be parsed\nin the order they are received. JavaScript files, JSON files, and objects will\nneed to namespace Custom Properties using the `customProperties` or\n`custom-properties` key.\n\n```js\nconst cachedObject = { customProperties: {} };\n\npostcssCustomProperties({\n  exportTo: [\n    'path/to/file.css',   // :root { --color: red; }\n    'and/then/this.js',   // module.exports = { customProperties: { '--color': 'red' } }\n    'and/then/this.mjs',  // export const customProperties = { '--color': 'red' } }\n    'and/then/that.json', // { \"custom-properties\": { \"--color\": \"red\" } }\n    'and/then/that.scss', // $color: red;\n    cachedObject,\n    customProperties =\u003e {\n      customProperties    // { '--color': 'red' }\n    }\n  ]\n});\n```\n\nSee example exports written to [CSS](test/export-properties.css),\n[JS](test/export-properties.js), [MJS](test/export-properties.mjs),\n[JSON](test/export-properties.json) and [SCSS](test/export-properties.scss).\n\n[cli-img]: https://img.shields.io/travis/postcss/postcss-custom-properties/master.svg\n[cli-url]: https://travis-ci.org/postcss/postcss-custom-properties\n[css-img]: https://github.com/postcss/postcss-custom-properties/workflows/test/badge.svg\n[css-url]: https://github.com/postcss/postcss-custom-properties/actions/workflows/test.yml?query=workflow/test\n[git-img]: https://img.shields.io/badge/support-chat-blue.svg\n[git-url]: https://gitter.im/postcss/postcss\n[npm-img]: https://img.shields.io/npm/v/postcss-custom-properties.svg\n[npm-url]: https://www.npmjs.com/package/postcss-custom-properties\n\n[CSS Custom Properties]: https://www.w3.org/TR/css-variables-1/\n[PostCSS]: https://github.com/postcss/postcss\n[PostCSS Custom Properties]: https://github.com/postcss/postcss-custom-properties\n","funding_links":[],"categories":["HarmonyOS","JavaScript"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostcss%2Fpostcss-custom-properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpostcss%2Fpostcss-custom-properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpostcss%2Fpostcss-custom-properties/lists"}