Pen Settings



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


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


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.


Save Automatically?

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.


                <!DOCTYPE html>
  <meta name="viewport" content="width=device-width">

    /** Apply theme inline in head to avoid flash of unstyled content. */
    const matchMediaDark = window.matchMedia('(prefers-color-scheme: dark)')
    const htmlClassList = document.querySelector('html').classList
    // Set the 'dark' class according to localStorage 'theme' setting.
    // Else if there's no stored 'theme', set the class per the system.
    function updateTheme() {
      localStorage.theme === 'dark' || (!('theme' in localStorage) && matchMediaDark.matches)
        ? htmlClassList.add('dark')
        : htmlClassList.remove('dark')
    // Apply theme when page loads.
    // Update 'dark' class when system theme is changed.
    matchMediaDark.addEventListener('change', updateTheme)
    // Toggle localStorage theme between 'dark' and 'light' then update the theme.
    function toggleTheme() {
        ? localStorage.theme = 'light'
        : localStorage.theme = 'dark'

    body {
      font-family: sans-serif;
      background-color: hsl(0deg 0% 80%);
      color: black;

    .dark body {
      background-color: hsl(0deg 0% 10%);
      color: white;

    a {
      color: hsl(200deg, 100%, 30%);

    .dark a {
      color: skyblue;

    button {
      background-color: transparent;
      color: black;
      border-width: 1px;
      border-radius: 6px;

    .dark button {
      color: white;

    <button onclick="toggleTheme()">Toggle Theme</button>

  <h1>Dark Mode Switcher Demo</h1>
    Click the button above to switch themes!<br>
    All this really does is add or remove the 'dark' class from the parent HTML element.
    The default system theme should load initially, but a user can override it if they want.<br>
    The selected theme will be saved in localStorage and survive a page reload.
  <a href="">Full Blog Post and Explanation</a>