<input type="checkbox" id="toggle" class="toggle sr-only" />

<div class="theme-container">
  <label for="toggle">
    <span>Switch light/dark mode</span>
  </label>
  <div class="container">
    <h1>Switch from light to dark mode using the toggle(^_^)</h1>
    <div class="node">
      <p>Using the :checked pseudo-class selector, one can style descendants and subsequent siblings of a checkbox when it is in checked state.</p>
      <p>Having both a checkbox for enabling dark mode and an element containing all other content on the page on the same level of the DOM tree allows us to offer a CSS-only dark mode of a web page.</p>
      <p>macOS Mojave adds a Dark Mode for native apps that makes you look approximately 78 percent cooler when using the computer. In Safari Technology Preview 68, it’s now available on webpages too! Here’s how I added support to this website.</p>
      <div class="action">
        <button>More...</button>
      </div>
    </div>
  </div>
</div>
@import url('//fonts.googleapis.com/css?family=Lato:400,400italic,700|Sansita+One');
@import url("https://fonts.googleapis.com/css?family=Merriweather:400,400i,700");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100vw;
  min-height: 100vh;
}

body {
  display: flex;
  justify-content: center;
}

.theme-container {
  flex: 1;
  width: 100vw;
  display: flex;
  justify-content: center;
  padding-top: 130px;
}

.container {
  max-width: 80vw;
  width: 60vw;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1 {
  font-family: "Sansita One", serif;
  font-size: 2rem;
  margin-bottom: 1vh;
}

.node {
  
  &::before {
    content: '';
    float: left;
    width: 546px;
    height: 805px;
    background: url('https://www.footyrenders.com/render/Neymar-45.png');
    background-size: cover;
    shape-outside: polygon(55px -1px, 9.57% 8.45%, 15.06% 17.15%, 0.41% 20.5%, -6.92% 29.07%, -22.67% 35.16%, -50.89% 41.37%, -75.8% 43.73%, -79.44% 49.93%, -58.94% 52.06%, -47.95% 47.33%, -3.26% 39.75%, -9.85% 47.7%, -39.52% 51.3%, -64.43% 58.76%, -73.59% 77.77%, -94.47% 84.85%, -93.73% 90.56%, -53.07% 84.1%, -40.26% 67.45%, 0.77% 67.58%, -8.42% 80.59%, -21.22% 90.42%, -20.84% 99.38%, -4.57% 97.33%, 13.13% 101.34%, 28.72% 94.26%, 43.75% 74.89%, 56.35% 62.5%, 76.74% 24.41%, 101.7% 17.48%, 101.87% 14.32%, 92.52% 11.73%, 74.31% 6.78%, 57.63% 1.97%);
    shape-margin: 10px;
    margin-left: -273px;
  }
}

p {
  font-family: Merriweather, serif;
  font-size: 1.1rem;
  line-height: 1.6rem;
  margin: 1rem 0;
}

button {
  -webkit-appearance: none;
  background-color: transparent;
  background-repeat: no-repeat;
  background-image: linear-gradient(-60deg, #ff4cff 0%, #ff4cff 41.6%, #5bf390 41.6%, #5bf390 100%), linear-gradient(-60deg, #ff4cff 0%, #ff4cff calc(100% - 41.6%), #5bf390 calc(100% - 41.6%), #5bf390 100%);
  background-position: 0 0, 0 100%, 0 0, 100% 0;
  background-size: 100% 0.3em, 100% 0.3em, calc(100% + 0.6em) 100%, 100% calc(100% + 0.6em);
  border: none;
  border-left: 0.3em solid #5bf390;
  border-right: 0.3em solid #ff4cff;
  padding: 1.3em 2.8em;
  line-height: 1;
  overflow: hidden;
  position: relative;
  font-size: 1em;
  font-weight: 400;
  transition: all 0.4s;
  outline: none !important;
  font-family: "Sansita One", serif;
  color: var(--c-text);
  
  &::before,
  &::after {
    content: '';
    display: block;
    position: absolute;
    z-index: -1;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-repeat: no-repeat;
    transition: all 0.4s;
    
  }
  
  &::before {
    background-image: linear-gradient(-66deg, transparent 0%, transparent 50%, #5bf390 50%, #5bf390 100%);
    transform: translateX(calc(-100% + 41.6%));
  }
  
  &::after {
    background-image: linear-gradient(114deg, transparent 0%, transparent 50%, #ff4cff 50%, #ff4cff 100%);
    transform: translateX(calc(100% - 41.6%));
  }
  
  &:hover,
  &:active{
    // color: white;
    
    &::before,
    &::after {
      transform: translateX(0);
    }
  }
}
.sr-only{ 
  position: absolute; 
  height: 1px; 
  width: 1px; 
  clip: rect(1px 1px 1px 1px); 
  clip: rect(1px,1px,1px,1px); 
  clip-path: polygon(0px 0px, 0px 0px, 0px 0px); 
  overflow: hidden !important; 
}

label {
  padding: 20px;
  margin: 60px;
  transition: background-color 200ms ease-in-out;
  width: 120px;
  height: 50px;
  border-radius: 50px;
  text-align: center;
  background-color: slateGray;
  box-shadow: -4px 4px 15px inset rgba(0, 0, 0, 0.4);
  position: absolute;
  top: 0;
  right: 0;
  font-family: "Sansita One", serif;
  
  &::before,
  &::after {
    font-size: 2rem;
    position: absolute;
    transform: translate3d(0, -50%, 0);
    top: 50%;
  }
  
  &::before {
    content: '\263C';
    right: 100%;
    margin-right: 10px;
    color: orange;
    font-size: 2rem;
    line-height: 1;
    bottom: -7px;
  }
  
  &::after {
    content: '\263E';
    left: 100%;
    margin-left: 10px;
    color: lightSlateGray;
  }
  
  span {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translate(-50%, 0);
    white-space: nowrap;
    
    &::after {
      position: absolute;
      top: calc(100% + 15px);
      left: 34px;
      width: 40px;
      height: 40px;
      content: '';
      border-radius: 50%;
      background-color: lightBlue;
      transition: transform 200ms, background-color 200ms;
      box-shadow: -3px 3px 8px rgba(0, 0, 0, 0.4);
    }
  }
}

input[type="checkbox"]:checked ~ .theme-container label {
  background-color: lightSlateGray;
  
  &::before {
    color: lightSlateGray;
  }
  
  &::after {
    color: turquoise;
  }
  
  span::after {
    transform: translate3d(68px, 0, 0);
  }
}

// dark & light mode
:root {
  /* Light theme */
  --c-text: #333;
  --c-background: #fff;
}

.theme-container {
  color: var(--c-text);
  background-color: var(--c-background);
}

input[type="checkbox"]:checked ~ .theme-container {
  filter: invert(100) hue-rotate(180deg);
  
  img {
    filter: invert(100) hue-rotate(180deg);
  }
  
  .node::before {
    filter: invert(100) hue-rotate(180deg);
  }
}
View Compiled
document.addEventListener('DOMContentLoaded', function () {
  const checkbox = document.querySelector('.toggle');

  checkbox.checked = localStorage.getItem('darkMode') === 'true';

  checkbox.addEventListener('change', function (event) {
    localStorage.setItem('darkMode', event.currentTarget.checked);
  });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.