• Stars
    star
    529
  • Rank 83,204 (Top 2 %)
  • Language
    HTML
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add a dark-mode theme toggle with a Bootstrap Custom Switch

LICENSE GitHub Super-Linter code style: prettier Best of JS GitHub Stars NPM Downloads

🌓 Dark Mode Switch

Add a dark-mode theme toggle with a Bootstrap Custom Switch.

  • Uses local storage to save preference
  • Only 383 Bytes minified and gzipped!

Quick start

Several quick start options are available:

  • Download the latest release
  • Clone the repo git clone https://github.com/coliff/dark-mode-switch.git
  • Install with npm npm install dark-mode-switch
  • Install with yarn yarn add dark-mode-switch

Usage

  1. Add your custom switch for the Dark Mode toggle followed by the dark-mode-switch.min.js script:

Bootstrap 4.x

<div class="custom-control custom-switch">
  <input type="checkbox" class="custom-control-input" id="darkSwitch" />
  <label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
<script src="dark-mode-switch.min.js"></script>

Bootstrap 5.x

<div class="form-check form-switch">
  <input type="checkbox" class="form-check-input" id="darkSwitch" />
  <label class="custom-control-label" for="darkSwitch">Dark Mode</label>
</div>
<script src="dark-mode-switch.min.js"></script>
  1. Edit the dark-mode.css to suit your site - the one included here is a basic example.

How it works

Turning dark mode on will add data-theme="dark" to the body tag. You can use CSS to target the elements on the page like so:

[data-theme="dark"] {
  background-color: #111 !important;
  color: #eee;
}

Demo

Bootstrap 5 Demo page

Browser Support

Works well with all the browsers supported by Bootstrap 4 and Bootstrap 5

To Enable DarkMode in Android Webview

WebSettings.setDomStorageEnabled(true)

Credits

Created thanks to the excellent dark-theme and local storage tutorials over at codyhouse.co.

More Repositories

1

bootstrap-ie7

Bootstrap 3 CSS for IE7
575
star
2

bootstrap-ie8

Bootstrap 4 for IE8 and IE9
HTML
280
star
3

bootstrap-ie11

Internet Explorer 11 compatibility solution for Bootstrap 5
HTML
93
star
4

bootstrap-print-css

Print Stylesheet for Bootstrap 5
40
star
5

inputmodes.com

Testing inputmode
39
star
6

awesome-website-testing-tools

Resource of web-based testing and validation tools
31
star
7

bootstrap-show-password-toggle

A show password as text toggle for Bootstrap forms
HTML
28
star
8

html5-email-regex

Pure HTML5 Email validator which checks valid TLDs with no JavaScript
HTML
17
star
9

bootstrap-rfs

Easy-to-add CSS for adding Responsive Font Sizes (RFS) to Bootstrap 4
15
star
10

Brackets-HTML5CodeHints

Extend Brackets own code hints with more HTML5 elements and attributes such as Picture, Srcset, Template +more.
JavaScript
14
star
11

freshdesk-messaging-facade

A faster Freshdesk Messaging (formerly Freshchat) Facade
JavaScript
9
star
12

geoip-db-country-select

🗺️ Auto select country from a dropdown using GEOIP DB and jQuery
HTML
7
star
13

Brackets-CSSCodeHints

Extends Bracket's CSS code hints with more attributes; clip-path, image-rendering, tab-size, touch-action and more
JavaScript
6
star
14

keyata

Chrome extension to enable media keys for music/video playback
JavaScript
5
star
15

font-awesome-background-svg

font-awesome-background-svg
CSS
3
star
16

bootstrap-5-migrate-tool

A command-line tool designed to help you upgrade your Bootstrap 4 projects to Bootstrap 5
HTML
2
star
17

sender-brand-icon-avatars-for-email

The .CSV used to generate the CSS for Sender Avatar Icons Browser Extension
2
star
18

new.caniuse.email

Rebuilt from the groundup with Jekyll
Ruby
2
star
19

purgecss-test

Testing PurgeCSS with Hugo
CSS
1
star
20

coliff

1
star
21

dotfiles

🔧 .files
1
star
22

prevent-pii-tracking-in-google-analytics

Prevent PII being tracked in Google Analytics
HTML
1
star
23

bootstrap-forced-colors-css

Improves the accessibility of Bootstrap 5 for Windows users using High Contrast themes
HTML
1
star
24

WP-SmartAppBanner

WordPress plugin which allows you to quickly and easily add an iOS Smart App Banner
PHP
1
star