{"id":18259986,"url":"https://github.com/hungrybluedev/theme-switcher","last_synced_at":"2026-05-04T20:38:33.932Z","repository":{"id":109592561,"uuid":"501967514","full_name":"hungrybluedev/theme-switcher","owner":"hungrybluedev","description":"Modular JS library that allows easy theme-switching for any website.","archived":false,"fork":false,"pushed_at":"2022-06-12T12:26:51.000Z","size":1097,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-08T23:44:29.292Z","etag":null,"topics":["css","javascript","theme-switcher","themes"],"latest_commit_sha":null,"homepage":"","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/hungrybluedev.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":"2022-06-10T08:44:43.000Z","updated_at":"2024-10-13T04:42:51.000Z","dependencies_parsed_at":"2023-07-29T01:32:50.124Z","dependency_job_id":null,"html_url":"https://github.com/hungrybluedev/theme-switcher","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/hungrybluedev/theme-switcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hungrybluedev%2Ftheme-switcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hungrybluedev%2Ftheme-switcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hungrybluedev%2Ftheme-switcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hungrybluedev%2Ftheme-switcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hungrybluedev","download_url":"https://codeload.github.com/hungrybluedev/theme-switcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hungrybluedev%2Ftheme-switcher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262181059,"owners_count":23271319,"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":["css","javascript","theme-switcher","themes"],"created_at":"2024-11-05T10:41:24.323Z","updated_at":"2026-05-04T20:38:33.845Z","avatar_url":"https://github.com/hungrybluedev.png","language":"HTML","funding_links":["https://github.com/sponsors/hungrybluedev)!"],"categories":[],"sub_categories":[],"readme":"# [Theme Switcher](https://theme-switcher.com/)\n\n![npm (scoped)](https://img.shields.io/npm/v/@hungrybluedev/theme-switcher)\n![GitHub file size in bytes](https://img.shields.io/github/size/hungrybluedev/theme-switcher/dist/switch.js)\n![npm](https://img.shields.io/npm/dw/@hungrybluedev/theme-switcher)\n![GitHub](https://img.shields.io/github/license/hungrybluedev/theme-switcher)\n\n_Theming is hard. Let's make it easier._\n\n[![Screenshot of demo](https://demo.theme-switcher.com/images/theme-switcher.png)](https://demo.theme-switcher.com/)\n\nSample: [demo.theme-switcher.com](https://demo.theme-switcher.com/)\n\n## Introduction\n\nI wanted a modular system for theming for all of my projects. I deal with HTML, CSS, and plain JavaScript. Therefore, I wanted my approach to be as simple and un-intrusive as possible. This project is my attempt as standardising my theme switching code across all of my projects. There are still a few things that must be taken care of manually, such as defining CSS variables for the themes, using the variables in a consistent format, ensuring a settings page. However, this project hopes to provide a standard way to manage user preference for themes.\n\n## Usage\n\nSee the [static](https://github.com/hungrybluedev/theme-switcher/tree/main/static) folder for an example on how to structure your code. Essentially, it is best to have a dedicated **Settings** page where the user can configure the theme. Any page is valid as a settings page as long as:\n\n1. It has a `\u003cform\u003e` element with `id=\"theme-switcher-form\"`.\n2. The form has `\u003cinput\u003e` elements, one for each supported theme.\n3. All input elements must have `name=\"theme-choice\"` and id+value=`(theme-name)-theme`.\n\nIn summary, a `settings.html` file should be have something like:\n\n```html\n...\n\u003cform id=\"theme-switcher-form\"\u003e\n  \u003cp\u003eSelect your preferred theme:\u003c/p\u003e\n\n  \u003cdiv\u003e\n    \u003cinput\n      type=\"radio\"\n      id=\"light-theme\"\n      name=\"theme-choice\"\n      value=\"light-theme\"\n    /\u003e\n    \u003clabel for=\"light-theme\"\u003eLight\u003c/label\u003e\n  \u003c/div\u003e\n\n  \u003cdiv\u003e\n    \u003cinput\n      type=\"radio\"\n      id=\"dark-theme\"\n      name=\"theme-choice\"\n      value=\"dark-theme\"\n    /\u003e\n    \u003clabel for=\"dark-theme\"\u003eDark\u003c/label\u003e\n  \u003c/div\u003e\n\n  ...\n\u003c/form\u003e\n...\n```\n\nAdditionally, the see [theme.css](https://github.com/hungrybluedev/theme-switcher/blob/main/static/theme.css) for an example of how to configure your themes with **CSS variables**. There should be a `light` theme by default. Add more as you please. An example CSS theme configuration is:\n\n```css\nhtml {\n  --primary: #bd1767;\n  --secondary: #271a6f;\n  --bg-primary: #eee;\n  --bg-secondary: #d5d5d5;\n  --fg-primary: #333;\n  --fg-secondary: #444;\n}\n\nhtml[data-theme=\"light\"] {\n  --primary: #bd1767;\n  --secondary: #271a6f;\n  --bg-primary: #eee;\n  --bg-secondary: #d5d5d5;\n  --fg-primary: #333;\n  --fg-secondary: #444;\n}\n\nhtml[data-theme=\"dark\"] {\n  --primary: #e679ad;\n  --secondary: #63aff1;\n  --bg-primary: #353535;\n  --bg-secondary: #292929;\n  --fg-primary: #fafafa;\n  --fg-secondary: #d2d2d2;\n}\n```\n\nThe next part is easy. Just have a `\u003cscript\u003e` tag on all the HTML files you are serving with the following code:\n\n```html\n\u003cscript\n  src=\"https://unpkg.com/@hungrybluedev/theme-switcher@latest/dist/switch.js\"\n  type=\"module\"\n  defer\n\u003e\u003c/script\u003e\n```\n\nIf you prefer having the source code served from your server, you can use save it from the unpkg link and use the `switch.js` file directly.\n\n## License\n\nThis project is distributed under the MIT license. See the [LICENSE](https://github.com/hungrybluedev/theme-switcher/blob/main/LICENSE) file for more information.\n\n## Contact\n\nVisit my [contact](https://hungrybluedev.in/contact/) page to get in touch with me. Consider starring the repo if you like it. If you're really happy with it, consider contributing to it or [sponsoring me](https://github.com/sponsors/hungrybluedev)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhungrybluedev%2Ftheme-switcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhungrybluedev%2Ftheme-switcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhungrybluedev%2Ftheme-switcher/lists"}