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

              
                <!--
  Copyright (c) 2020 - present, DITDOT Ltd.
  https://www.ditdot.hr/en
-->
<div class='wrapper'>
    <svg class='lightsaber first' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 97.01 97.1">
        <polygon class='handle'
            points="97.01 89.78 93.61 86.37 95.29 84.69 84.59 73.99 73.9 84.69 84.59 95.38 86.28 93.7 89.68 97.1 97.01 89.78" />
        <rect class='handle' x="66.92" y="72.23" width="15.13" height="4.68"
            transform="translate(-30.92 74.51) rotate(-45)" />
        <rect class='handle' x="60.5" y="65.81" width="15.13" height="4.68"
            transform="translate(-28.26 68.09) rotate(-45)" />
        <rect class='handle' x="51.88" y="59.39" width="19.53" height="4.68"
            transform="translate(-25.6 61.67) rotate(-45)" />
        <path class='blade first-blade'
            d="M59.57,54.27,6.41,1.11c-2.7-2.7-5.18.36-5.39.45A3.5,3.5,0,0,0,1,6.5L54.18,59.66Z" />
    </svg>
    <svg class='lightsaber second' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 97.01 97.1">
        <polygon class='handle'
            points="97.01 89.78 93.61 86.37 95.29 84.69 84.59 73.99 73.9 84.69 84.59 95.38 86.28 93.7 89.68 97.1 97.01 89.78" />
        <rect class='handle' x="66.92" y="72.23" width="15.13" height="4.68"
            transform="translate(-30.92 74.51) rotate(-45)" />
        <rect class='handle' x="60.5" y="65.81" width="15.13" height="4.68"
            transform="translate(-28.26 68.09) rotate(-45)" />
        <rect class='handle' x="51.88" y="59.39" width="19.53" height="4.68"
            transform="translate(-25.6 61.67) rotate(-45)" />
        <path class='blade second-blade'
            d="M59.57,54.27,6.41,1.11c-2.7-2.7-5.18.36-5.39.45A3.5,3.5,0,0,0,1,6.5L54.18,59.66Z" />
    </svg>
    <button class='btn'>Toggle mode</button>
</div>

<p class="caption">
        <a href="https://www.ditdot.hr/en/dark-mode-website-tutorial"
            title="ditdot.hr" target="_blank">Visit how-to article on our blog</a></p>
              
            
!

CSS

              
                /*
    Copyright (c) 2020 - present, DITDOT Ltd.
    https://www.ditdot.hr/en
*/

/* default, light mode styles set with variables */
:root {
  --color-background: #f9f9f9;
  --color-default: #000;
  --color-accent-1: deepskyblue;
  --color-accent-2: violet;
}

body {
  background-color: var(--color-background);
  margin: 0;
  padding: 0;
  max-height: 100%;
  overflow: hidden;
}

.wrapper {
  position: relative;
  width: 100%;
  height: 85vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Toggle button */
.btn {
  position: absolute;
  padding: 10px 16px;
  background-color: var(--color-background);
  border: var(--color-default) solid 3px;
  color: var(--color-default);
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
}

/* SVG lightsabers */
.lightsaber {
  width: 200px;
  position: absolute;
}

.lightsaber.second {
  transform: rotate(90deg);
}

.first-blade {
  fill: var(--color-accent-1);
}

.second-blade {
  fill: var(--color-accent-2);
}

.handle {
  fill: var(--color-default);
}

/*dark-mode styles*/
.dark-mode {
  --color-background: #000;
  --color-default: #f9f9f9;
  --color-accent-1: cyan;
  --color-accent-2: magenta;
}

.dark-mode .lightsaber path {
  transition: fill .12s ease-in;
}

p.caption {
  text-align: center;
  font-size: 13px;
  padding-bottom: 30px;
}

p.caption a {
  color: var(--color-default);
}
              
            
!

JS

              
                /*
    Copyright (c) 2020 - present, DITDOT Ltd.
    https://www.ditdot.hr/en
*/

function load() {
  const button = document.querySelector(".btn");

  // MediaQueryList object
  const useDark = window.matchMedia("(prefers-color-scheme: dark)");

  // Toggles the "dark-mode" class based on if the media query matches
  function toggleDarkMode(state) {
    // Older browser don't support the second parameter in the
    // classList.toggle method so you'd need to handle this manually
    // if you need to support older browsers.
    document.documentElement.classList.toggle("dark-mode", state);
  }

  // Initial setting
  toggleDarkMode(useDark.matches);

  // Listen for changes in the OS settings
  useDark.addListener((evt) => toggleDarkMode(evt.matches));

  // Toggles the "dark-mode" class on click
  button.addEventListener("click", () => {
    document.documentElement.classList.toggle("dark-mode");
  });
}

window.addEventListener("DOMContentLoaded", load);

              
            
!
999px

Console