{"id":13647328,"url":"https://github.com/csstools/css-prefers-color-scheme","last_synced_at":"2025-04-22T02:31:17.733Z","repository":{"id":45651714,"uuid":"138062445","full_name":"csstools/css-prefers-color-scheme","owner":"csstools","description":"Use light or dark color themes in CSS","archived":true,"fork":false,"pushed_at":"2021-12-16T12:02:50.000Z","size":460,"stargazers_count":99,"open_issues_count":0,"forks_count":8,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-06T11:50:25.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/csstools/postcss-plugins/tree/main/plugins/css-prefers-color-scheme","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/csstools.png","metadata":{"files":{"readme":"README-BROWSER.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":"2018-06-20T17:04:46.000Z","updated_at":"2025-03-03T16:03:54.000Z","dependencies_parsed_at":"2022-09-14T12:30:42.960Z","dependency_job_id":null,"html_url":"https://github.com/csstools/css-prefers-color-scheme","commit_stats":null,"previous_names":["csstools/css-prefers-interface"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-prefers-color-scheme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-prefers-color-scheme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-prefers-color-scheme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csstools%2Fcss-prefers-color-scheme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csstools","download_url":"https://codeload.github.com/csstools/css-prefers-color-scheme/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248184188,"owners_count":21061299,"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-08-02T01:03:29.714Z","updated_at":"2025-04-22T02:31:17.482Z","avatar_url":"https://github.com/csstools.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Prefers Color Scheme [\u003cimg src=\"https://jonathantneal.github.io/js-logo.svg\" alt=\"\" width=\"90\" height=\"90\" align=\"right\"\u003e][Prefers Color Scheme]\n\n[![NPM Version][npm-img]][npm-url]\n[![Build Status][cli-img]][cli-url]\n[![Support Chat][git-img]][git-url]\n\n[Prefers Color Scheme] applies color schemes with fallbacks provided by the\n[Prefers Color Scheme PostCSS plugin](README-POSTCSS.md).\n\n```js\n// initialize prefersColorScheme (applies the current OS color scheme, if available)\nconst prefersColorScheme = require('css-prefers-color-scheme')();\n\n// apply \"dark\" queries (you can also apply \"light\")\nprefersColorScheme.scheme = 'dark';\n```\n\n[Prefers Color Scheme] works in all major browsers, including Safari 6+ and\nInternet Explorer 9+ without any polyfills.\n[See it for yourself.](https://app.crossbrowsertesting.com/public/i76b092cd2b52b86/screenshots/z25c0ccdfcc9c9b8956f?size=medium\u0026type=windowed)\n\nTo maintain compatibility with browsers supporting `prefers-color-scheme`, the\nlibrary will remove `prefers-color-scheme` media queries in favor of\ncross-browser compatible `color-index` media queries. This ensures a seemless\nexperience, even when JavaScript is unable to run.\n\n## Usage\n\nUse [Prefers Color Scheme] to activate your `prefers-color-scheme` queries:\n\n```js\nconst prefersColorScheme = require('css-prefers-color-scheme')();\n```\n\nBy default, the current OS color scheme is applied if your browser supports it.\nOtherwise, the light color scheme is applied. You may override this by passing\nin a color scheme.\n\n```js\nconst prefersColorScheme = require('css-prefers-color-scheme')('dark');\n```\n\nThe `prefersColorScheme` object returns the following properties — `value`,\n`hasNativeSupport`, `onChange`, and `removeListener`.\n\n### value\n\nThe `value` property returns the currently preferred color scheme, and it can\nbe changed.\n\n```js\nconst prefersColorScheme = require('css-prefers-color-scheme')();\n\n// log the preferred color scheme\nconsole.log(prefersColorScheme.scheme);\n\n// apply \"dark\" queries\nprefersColorScheme.scheme = 'dark';\n```\n\n### hasNativeSupport\n\nThe `hasNativeSupport` boolean represents whether `prefers-color-scheme` is\nsupported by the browser.\n\n### onChange\n\nThe optional `onChange` function is run when the preferred color scheme is\nchanged, either from the OS or manually.\n\n### removeListener\n\nThe `removeListener` function removes the native `prefers-color-scheme`\nlistener, which may or may not be applied, depending on your browser support.\nThis is provided to give you complete control over plugin cleanup.\n\n[cli-img]: https://img.shields.io/travis/csstools/css-prefers-color-scheme/master.svg\n[cli-url]: https://travis-ci.org/csstools/css-prefers-color-scheme\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/css-prefers-color-scheme.svg\n[npm-url]: https://www.npmjs.com/package/css-prefers-color-scheme\n\n[PostCSS]: https://github.com/postcss/postcss\n[Prefers Color Scheme]: https://github.com/csstools/css-prefers-color-scheme\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fcss-prefers-color-scheme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsstools%2Fcss-prefers-color-scheme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsstools%2Fcss-prefers-color-scheme/lists"}