{"id":19354596,"url":"https://github.com/fallaciousreasoning/postcss-plugin-darkmode","last_synced_at":"2026-05-06T13:32:25.890Z","repository":{"id":58413923,"uuid":"531299622","full_name":"fallaciousreasoning/postcss-plugin-darkmode","owner":"fallaciousreasoning","description":"PostCSS plugin for an @darkmode AtRule","archived":false,"fork":false,"pushed_at":"2022-09-12T00:12:14.000Z","size":118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T11:40:50.318Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/fallaciousreasoning.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-09-01T00:00:47.000Z","updated_at":"2022-09-01T00:01:11.000Z","dependencies_parsed_at":"2023-01-18T04:15:27.809Z","dependency_job_id":null,"html_url":"https://github.com/fallaciousreasoning/postcss-plugin-darkmode","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallaciousreasoning%2Fpostcss-plugin-darkmode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallaciousreasoning%2Fpostcss-plugin-darkmode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallaciousreasoning%2Fpostcss-plugin-darkmode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fallaciousreasoning%2Fpostcss-plugin-darkmode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fallaciousreasoning","download_url":"https://codeload.github.com/fallaciousreasoning/postcss-plugin-darkmode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240466792,"owners_count":19805862,"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-11-10T05:02:44.957Z","updated_at":"2026-05-06T13:32:25.827Z","avatar_url":"https://github.com/fallaciousreasoning.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postcss-plugin-darkmode\n\n[PostCSS] plugin for an @darkmode AtRule.\n\n[PostCSS]: https://github.com/postcss/postcss\n\nThe plugin allows you to toggle light and dark mode at different levels of the\nDOM, without requiring any JavaScript at all! It works by extracting properties\nused in Light \u0026 Dark mode into CSS variables.\n\n```html\n\u003chtml\u003e\n  \u003cbody\u003e \u003c!-- Uses the users color scheme, no theme is specified --\u003e\n    \u003cdiv data-theme=\"dark\"\u003e \u003c!-- This element, and all descendants use the dark theme --\u003e\n      \u003cdiv\u003e \u003c!-- So this is dark! --\u003e\n        \u003cdiv\u003e\u003c/div\u003e \u003c!-- And this! --\u003e\n        \u003cdiv data-theme=\"light\"\u003e \u003c!-- But this specifies the light theme, so it and it's children are light --\u003e\n          \u003cdiv\u003e \u003c/div\u003e \u003c!-- Light too! --\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Examples\n\n### CSS\n```css\n.foo {\n  padding: 12px;\n  background: pink;\n\n  display: flex;\n  flex-direction: column;\n}\n\n@darkmode {\n  .foo {\n    background: red;\n    flex-direction: row;\n  }\n}\n```\n\n```css\n:root, [data-theme=light] {\n  --\\.foo_background: pink;\n  --\\.foo_flex-direction: column;\n}\n\n[data-theme=dark] {\n  --\\.foo_background: red;\n  --\\.foo_flex-direction: row;\n}\n\n@media (prefers-color-scheme: dark) {\n  :root {\n    --\\.foo_background: red;\n    --\\.foo_flex-direction: row;\n  }\n}\n\n.foo {\n  padding: 12px;\n  display: flex;\n  background: var(--\\.foo_background);\n  flex-direction: var(--\\.foo_flex-direction);\n}\n```\n\n### Sass\n\n```sass\n.foo {\n  padding: 12px;\n  background: pink;\n  display: flex;\n  flex-direction: column;\n\n  @darkmode {\n    background: red;\n    flex-direction: row;\n  }\n}\n```\n\n```css\n:root, [data-theme=light] {\n  --\\.foo_background: pink;\n  --\\.foo_flex-direction: column;\n}\n\n[data-theme=dark] {\n  --\\.foo_background: red;\n  --\\.foo_flex-direction: row;\n}\n\n@media (prefers-color-scheme: dark) {\n  :root {\n    --\\.foo_background: red;\n    --\\.foo_flex-direction: row;\n  }\n}\n\n.foo {\n  padding: 12px;\n  display: flex;\n  background: var(--\\.foo_background);\n  flex-direction: var(--\\.foo_flex-direction);\n}\n```\n\n## Options\n\n|                | Default | Description | Example Alternative\n| -------------- | ------- | ----------- | ------\n| Light Selector | `[data-theme=light]` | Used to select an elements with light mode forced | `.light`\n| Dark Selector | `[data-theme=dark]` | Used to select elements with dark mode forced. | `.dark`\n\n## Usage\n\n**Step 1:** Install plugin:\n\n```sh\nnpm install --save-dev postcss postcss-plugin-darkmode\n```\n\n**Step 2:** Check you project for existed PostCSS config: `postcss.config.js`\nin the project root, `\"postcss\"` section in `package.json`\nor `postcss` in bundle config.\n\nIf you do not use PostCSS, add it according to [official docs]\nand set this plugin in settings.\n\n**Step 3:** Add the plugin to plugins list:\n\n```diff\nmodule.exports = {\n  plugins: [\n+   require('postcss-plugin-darkmode'),\n    require('autoprefixer')\n  ]\n}\n```\n\n[official docs]: https://github.com/postcss/postcss#usage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffallaciousreasoning%2Fpostcss-plugin-darkmode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffallaciousreasoning%2Fpostcss-plugin-darkmode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffallaciousreasoning%2Fpostcss-plugin-darkmode/lists"}