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

              
                <button
  class="dark-toggler"
  aria-label="Toggle color mode"
  title="Toggle color mode"
  data-theme-toggle
>
  <div class="toggler-icon"></div>
</button>
              
            
!

CSS

              
                html {
  --color-background: #fffcf0;
  --color-background-shade: #fbf3d9;
  --color-text: #22211d;
  --color-text-shade: #575650;
  --color-primary: #147d82;
  background-color: var(--color-background);
  color: var(--color-text);
  height: 100%;
}  
 html[data-theme="dark"] {
  --color-background: #100f0f;
  --color-background-shade: #202424;
  --color-text: #d2dee1;
  --color-text-shade: #989f9f;
  --color-primary: #62aba4;
}
body {
  height: 100%;
}
.dark-toggler {
  background: unset;
  border: none;
  cursor: pointer;
}
.dark-toggler:hover .toggler-icon {
  background-color: var(--color-primary);
}
.toggler-icon {
  width: 18px;
  height: 18px;
  background-color: var(--color-text);
  transition: background-color 0.2s ease-in-out;
  -webkit-mask-size: 18px;
  -webkit-mask-position: 50% 50%;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='currentColor' %3E%3Cpath fill-rule='evenodd' d='M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z' clip-rule='evenodd' /%3E%3C/svg%3E");
}
html[data-theme="dark"] .toggler-icon {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='currentColor' viewBox='0 0 24 24' %3E%3Cpath d='M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z' /%3E%3C/svg%3E");
}
              
            
!

JS

              
                let currentTheme = getDefaultTheme();
setTheme(currentTheme);

addButtonThemeListener();

/**
 * Listens for the click of the button and execute the theme change
**/
function addButtonThemeListener() {
  const buttonToggler = document.querySelector("[data-theme-toggle]");
  buttonToggler.addEventListener("click", () => {
	  const newTheme = getNewTheme(currentTheme);
		setTheme(newTheme);
		currentTheme = newTheme;
    saveTheme(newTheme);
  });
}

/**
 * Get the default theme for the user
 * @return {String} theme - the theme of the user
 *
**/
function getDefaultTheme() {
  const systemSettingDark = window.matchMedia("(prefers-color-scheme: dark)");
  const systemSettingTheme = systemSettingDark.matches ? "dark" : "light";
  const savedTheme = getSavedTheme();
  return savedTheme ? savedTheme : systemSettingTheme;
}


/**
 * Returns the new theme
 * @param {String} theme - the current app theme, dark or light
 *
**/
function getNewTheme(theme) {
	return theme === "dark" ? "light" : "dark";
}

/**
 * Sets the theme globally
 * @param {String} theme - dark or light
 *
**/
function setTheme(theme) {
  const html = document.querySelector("html");
  html.setAttribute("data-theme", theme);
}

/**
 * Returns the theme saved in memory
 * @return {String} theme - the saved theme
 *
**/
function getSavedTheme() {
  return localStorage.getItem("theme");
}

/**
 * Saves theme in memory
 * @return {String} theme - the theme to save
 *
**/
function saveTheme(theme) {
  localStorage.setItem("theme", theme);
}
              
            
!
999px

Console