{"id":14990159,"url":"https://github.com/chrisburnell/theme-selector","last_synced_at":"2026-01-26T12:03:41.722Z","repository":{"id":215479948,"uuid":"738936580","full_name":"chrisburnell/theme-selector","owner":"chrisburnell","description":"A Web Component to set a site-wide theme preference using a native select element, saved to local storage.","archived":false,"fork":false,"pushed_at":"2024-02-18T20:40:47.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-04T13:51:14.667Z","etag":null,"topics":["component","components","custom-element","custom-elements","customelement","customelements","web-component","web-components","webcomponent","webcomponents"],"latest_commit_sha":null,"homepage":"https://chrisburnell.github.io/theme-selector/demo.html","language":"HTML","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/chrisburnell.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-04T11:48:04.000Z","updated_at":"2025-02-04T13:09:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"2cd7c8dd-dfac-4030-b545-2ec5f455ad73","html_url":"https://github.com/chrisburnell/theme-selector","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"55e57017462d08235d9028e8c0797e737b1d53b6"},"previous_names":["chrisburnell/theme-selector"],"tags_count":2,"template":false,"template_full_name":"daviddarnes/component-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisburnell%2Ftheme-selector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisburnell%2Ftheme-selector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisburnell%2Ftheme-selector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisburnell%2Ftheme-selector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisburnell","download_url":"https://codeload.github.com/chrisburnell/theme-selector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239859557,"owners_count":19708861,"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":["component","components","custom-element","custom-elements","customelement","customelements","web-component","web-components","webcomponent","webcomponents"],"created_at":"2024-09-24T14:19:38.166Z","updated_at":"2026-01-26T12:03:41.675Z","avatar_url":"https://github.com/chrisburnell.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `theme-selector`\n\nA Web Component for setting a website theme using a select element.\n\n**[Demo](https://chrisburnell.github.io/theme-selector/demo.html)** | **[Further reading](https://chrisburnell.com/theme-selector/)**\n\n## Examples\n\nGeneral usage example:\n\n```html\n\u003cscript type=\"module\" src=\"theme-selector.js\"\u003e\u003c/script\u003e\n\n\u003ctheme-selector\u003e\n    \u003cselect autocomplete=\"off\"\u003e\n        \u003coption value=\"light\"\u003e\n            Light\n        \u003c/option\u003e\n        \u003coption value=\"dark\"\u003e\n            Dark\n        \u003c/option\u003e\n    \u003c/select\u003e\n\u003c/theme-selector\u003e\n\n\u003cstyle\u003e\n    theme-selector:not(:defined) {\n        display: none;\n    }\n\u003c/style\u003e\n```\n\nExample using a custom storage key:\n\n```html\n\u003cscript type=\"module\" src=\"theme-selector.js\"\u003e\u003c/script\u003e\n\n\u003ctheme-selector data-key=\"color-scheme\"\u003e\n    \u003cselect autocomplete=\"off\"\u003e\n        \u003coption value=\"light\"\u003e\n            Light\n        \u003c/option\u003e\n        \u003coption value=\"dark\"\u003e\n            Dark\n        \u003c/option\u003e\n    \u003c/select\u003e\n\u003c/theme-selector\u003e\n\n\u003cstyle\u003e\n    theme-selector:not(:defined) {\n        display: none;\n    }\n\u003c/style\u003e\n```\n\nExample using a custom dark theme key:\n\n```html\n\u003cscript type=\"module\" src=\"theme-selector.js\"\u003e\u003c/script\u003e\n\n\u003ctheme-selector data-dark-theme=\"white-on-black\"\u003e\n    \u003cselect autocomplete=\"off\"\u003e\n        \u003coption value=\"black-on-white\"\u003e\n            Black on White\n        \u003c/option\u003e\n        \u003coption value=\"white-on-black\"\u003e\n            White on Black\n        \u003c/option\u003e\n    \u003c/select\u003e\n\u003c/theme-selector\u003e\n\n\u003cstyle\u003e\n    theme-selector:not(:defined) {\n        display: none;\n    }\n\u003c/style\u003e\n```\n\nExample with a custom transition class and duration to keep the class applied:\n\n```html\n\u003cscript type=\"module\" src=\"theme-selector.js\"\u003e\u003c/script\u003e\n\n\u003ctheme-selector data-transition-class=\"transitioning\" data-transition-duration=\"100\"\u003e\n    \u003cselect autocomplete=\"off\"\u003e\n        \u003coption value=\"light\"\u003e\n            Light\n        \u003c/option\u003e\n        \u003coption value=\"dark\"\u003e\n            Dark\n        \u003c/option\u003e\n    \u003c/select\u003e\n\u003c/theme-selector\u003e\n\n\u003cstyle\u003e\n    theme-selector:not(:defined) {\n        display: none;\n    }\n\u003c/style\u003e\n```\n\nExample targeting a specific element to apply the theme to:\n\n```html\n\u003cscript type=\"module\" src=\"theme-selector.js\"\u003e\u003c/script\u003e\n\n\u003ctheme-selector data-root-element=\".content\"\u003e\n    \u003cselect autocomplete=\"off\"\u003e\n        \u003coption value=\"light\"\u003e\n            Light\n        \u003c/option\u003e\n        \u003coption value=\"dark\"\u003e\n            Dark\n        \u003c/option\u003e\n    \u003c/select\u003e\n\u003c/theme-selector\u003e\n\n\u003cstyle\u003e\n    theme-selector:not(:defined) {\n        display: none;\n    }\n\u003c/style\u003e\n```\n\n## Features\n\nThis Web Component allows you to use a select element to control user-preferred theming across your website by setting a data attribute against the root element (or a defined selector query). Additionally saves the preference to local storage so that it can be applied on new page loads and maintained between user visits.\n\n## Installation\n\nYou have a few options (choose one of these):\n\n1. Install via [npm](https://www.npmjs.com/package/@chrisburnell/theme-selector): `npm install @chrisburnell/theme-selector`\n1. [Download the source manually from GitHub](https://github.com/chrisburnell/theme-selector/releases) into your project.\n1. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)\n\n### Usage\n\nMake sure you include the `\u003cscript\u003e` in your project (choose one of these):\n\n```html\n\u003c!-- Host yourself --\u003e\n\u003cscript type=\"module\" src=\"theme-selector.js\"\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- 3rd party CDN, not recommended for production use --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://www.unpkg.com/@chrisburnell/theme-selector/theme-selector.js\"\n\u003e\u003c/script\u003e\n```\n\n```html\n\u003c!-- 3rd party CDN, not recommended for production use --\u003e\n\u003cscript\n  type=\"module\"\n  src=\"https://esm.sh/@chrisburnell/theme-selector\"\n\u003e\u003c/script\u003e\n```\n\n## Credit\n\nWith thanks to the following people:\n\n- [David Darnes](https://darn.es) for creating this [Web Component repo template](https://github.com/daviddarnes/component-template)\n- [Andy Bell](https://piccalil.li/) for writing the article, [Create a user controlled dark or light mode](https://piccalil.li/tutorial/create-a-user-controlled-dark-or-light-mode/), which served as the initial inspiration and basis for building my own theming setup and eventually became this Web Component\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisburnell%2Ftheme-selector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisburnell%2Ftheme-selector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisburnell%2Ftheme-selector/lists"}