{"id":15980590,"url":"https://github.com/drwpow/postcss-scoped-styles","last_synced_at":"2025-04-04T18:44:42.894Z","repository":{"id":66331309,"uuid":"463672033","full_name":"drwpow/postcss-scoped-styles","owner":"drwpow","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-25T21:20:55.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-10T04:17:25.953Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/drwpow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-25T20:51:09.000Z","updated_at":"2022-02-25T20:52:13.000Z","dependencies_parsed_at":"2023-02-20T23:00:22.067Z","dependency_job_id":null,"html_url":"https://github.com/drwpow/postcss-scoped-styles","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"426c740c5873f70509d432f41f98c66242f5e211"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwpow%2Fpostcss-scoped-styles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwpow%2Fpostcss-scoped-styles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwpow%2Fpostcss-scoped-styles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwpow%2Fpostcss-scoped-styles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drwpow","download_url":"https://codeload.github.com/drwpow/postcss-scoped-styles/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234850,"owners_count":20905852,"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-10-08T00:21:02.181Z","updated_at":"2025-04-04T18:44:42.871Z","avatar_url":"https://github.com/drwpow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postcss-scoped-styles\n\nScope every selector within CSS with a class. Can either be a unique, randomized class per CSS file (default), or can be a class of your choosing.\n\nFast, lightweight, and zero dependencies.\n\n## Installation\n\n```\nnpm i postcss-scoped-styles\n```\n\n```js\n// postcss.config.mjs\nimport postcssScopedStyles from 'postcss-scoped-styles';\n\nexport default {\n  plugins: [postcssScopedStyles()],\n};\n```\n\nAny and all selectors you use will now be scoped:\n\n```diff\n- h1 {\n+ h1.gZHu1x {\n    font-size: 32px;\n  }\n\n- .button {\n+ .button.gZHu1x {\n    color: blue;\n  }\n\n- #text-input {\n+ #text-input.gZHu1x {\n    font-family: monospace;\n  }\n```\n\nHowever, you may opt out of this with the `:global()` selector (i.e. will remain as-written):\n\n```diff\n- :global(.button:hover) {\n+ .button:hover {\n    color: blue;\n  }\n```\n\nIt’s also important to note that `html` and `body` **won’t** be scoped either, as they can only appear in the document once (it also makes selecting them easier).\n\n## Options\n\n**scopedClass**\n\nBy default, a random 6-character class is added for each CSS document. You may customize that by providing a `scopedClass()` function that returns a string:\n\n```js\n// postcss.config.mjs\nimport postcssScopedStyles from 'postcss-scoped-styles';\n\nexport default {\n  plugins: [\n    postcssScopedStyles({\n      scopedClass({ uuid, selector }) {\n        return `my-scoped-class-${uuid}`; // .my-scoped-class-c10a6a\n      },\n    }),\n  ],\n};\n```\n\nThe callback provides `uuid` and `selector` in an object param for extra context, but you don’t have to use these to generate the class. `uuid` is the random string that would have been applied on its own. It will be randomized on every pass, but it will stay consistent within each CSS document.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrwpow%2Fpostcss-scoped-styles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrwpow%2Fpostcss-scoped-styles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrwpow%2Fpostcss-scoped-styles/lists"}