Moderrek / vanilla-theme

An example of how to create light and dark mode for vanilla HTML

Home Page:https://moderrek.github.io/vanilla-theme/

Repository from Github https://github.comModerrek/vanilla-themeRepository from Github https://github.comModerrek/vanilla-theme

🎨 Vanilla Theme

License Issues Forks Stars

This repo provides a simple example of a themes implmented using pure vanilla HTML, JS and CSS. It demonstrates how to create themes and a theme switches that respects the user's system preference and saves their choice for future visits.

image image image

🗺️ Overview

The example showcases:

  • 🔎 Automatic theme detection: Automatically applies the system's preferred color scheme. (light or dark mode)
  • ⚙️ Theme toggle: Allows users to manually switch between light and dark themes.
  • 💾 Persistent user preference: Saves the user's theme choice using local storage, so their preference is preserved across page reloads.
  • 👀 Listens to the theme system: If the system theme changes, the theme will be automatically changed on the website.

📂 Files Included

  1. index.html: Basic HTML structure with a theme toggle button.
  2. style.css: Example CSS with styling for LIGHT and DARK modes.
  3. script.js: JavaScript to handle theme switching, system theme and persistent storage.

💻 Usage

  1. Clone the repository
    git clone https://github.com/Moderrek/vanilla-theme
  2. Enter the project directory
    cd vanilla-theme
  3. Open index.html in your browser
  4. Explore files and learn.

🤝 Contribution

Feel free to fork the repository and modify the example as needed for your own projects. If you have any improvements or suggestions, please submit a pull request.

© LICENSE

MIT License

Copyright (c) 2024 Tymon Woźniak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

An example of how to create light and dark mode for vanilla HTML

https://moderrek.github.io/vanilla-theme/

License:MIT License


Languages

Language:CSS 34.4%Language:JavaScript 33.7%Language:HTML 31.9%