Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                @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);
  }
}
              
            
!

JS

              
                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);
  });
});
              
            
!
999px

Console