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

              
                    <div id="accessibility-prefs" class="accessibility-prefs">
      <a href="#" id="toggle-dark" class="toggle-dark button">Dark Mode</a>
      <a href="#" id="toggle-dark-reset" class="toggle-dark-reset button">Reset Preference</a>
    </div>


<div class="container">

  <h1>It was a dark and stormy night</h1>

  <p>Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs he was acquainted; moreover he suffered much by sea while trying to save his own life and bring his men safely home; but do what he might he could not save his men, for they perished through their own sheer folly in eating the cattle of the Sun-god Hyperion; so the god prevented them from ever reaching home. Tell me, too, about all these things, O daughter of Jove, from whatsoever source you may know them. 
  </p>
  

</div>
              
            
!

CSS

              
                /* IBM Plex Sans Variable Font */
@font-face {
  font-family: "Plex Sans VF";
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/IBMPlexSansVar-Roman.woff2")
    format("woff2-variations");
  font-weight: 100 700;
  font-stretch: 85% 100%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Sans VF";
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/IBMPlexSansVar-Italic.woff2")
    format("woff2-variations");
  font-weight: 100 700;
  font-stretch: 85% 100%;
  font-style: italic;
  font-display: swap;
}

:root {
  --text-size: 1.25rem;
  --text-vf-wght: 400;  
  --text-vf-wdth: 100;
  --text-vf-ital: normal;

  --color-dark: #3a3a3a;
  --color-light: #eee;
  
  --color-text: var(--color-dark);
  --color-background: var(--color-light);
  
  /* variable used to store user preference */
  --user-color-pref: 'unset';
}

body {
  background-color: var(--color-background);
  color: var(--color-text);
  transition: background-color 0.25s ease, color 0.25s ease;
}
.container {
  margin-left: auto;
  margin-right: auto;
  max-width: 95vw;
  width: 45em;
}

p {
  font-family: "Plex Sans VF", Arial, sans-serif;
  font-size: var(--text-size);
  font-stretch: calc( var(--text-vf-wdth) * 1% );
  font-style: var(--text-vf-ital);
  font-weight: var(--text-vf-wght);
}

h1 {
  font-family: "Plex Sans VF", Arial, sans-serif;
  font-size: calc(var(--text-size) * 2.75);
  font-stretch: 75%;
  /* set font-weight as a multiple of body weight so they scale together */
  font-weight: calc(var(--text-vf-wght) * 1.75);
}

@media (prefers-color-scheme:dark) {
  :root {
    /* flip the light and dark variables */
    --color-text: var(--color-light);
    --color-background: var(--color-dark);
  }
  p, 
  .dark p {
    font-weight: calc(var(--text-vf-wght) * 1.025);
    letter-spacing: 0.0125em;
  }
  .dark {
      /* flip the light and dark variables */
      --color-text: var(--color-light);
      --color-background: var(--color-dark);
  }
  .light {
    /* flip the light and dark variables */
    --color-text: var(--color-dark);
    --color-background: var(--color-light);
  }
  p, 
  .dark p {
    font-weight: calc(var(--text-vf-wght) * 1.025);
    letter-spacing: 0.0125em;
  }
  .light p {
    font-weight: calc(var(--text-vf-wght) * 1);
    letter-spacing: auto;
  }
}

.dark {
  /* flip the light and dark variables */
  --color-text: var(--color-light);
  --color-background: var(--color-dark);
}
.light {
  /* flip the light and dark variables */
  --color-text: var(--color-dark);
  --color-background: var(--color-light);
  letter-spacing: auto;
}
.dark p {
  font-weight: calc(var(--text-vf-wght) * 1.025);
  letter-spacing: 0.0125em;
}
.light p {
  font-weight: calc(var(--text-vf-wght) * 1);
  letter-spacing: auto;
}



/* Control buttons */
 
.button {
  background-color: var(--color-text);
  border: solid 1px var(--color-text);
  border-radius: 0.15em;
  color: var(--color-background);
  display: inline-block;
  font-family: "Plex Sans VF", Arial, sans-serif;
  padding: 0.2em 0.25em 0.15em;
  text-decoration: none; 
}

.toggle-dark {
  min-width: 9em;
}
.toggle-dark:after {
  content: ': default';
}
.toggle-dark.on:after {
  content: ': dark';
}
.toggle-dark.off:after {
  content: ': light';
}

              
            
!

JS

              
                

/* Light mode toggle */
if (!'classList' in document.createElement('span')) {
  document.getElementById('c-unsupported').classList.remove('hidden');
  document.getElementById('execute').setAttribute('disabled', 'disabled');
} else {
  if (document.getElementById('toggle-dark')) {
    document.getElementById('toggle-dark').addEventListener('click', function(e) {
      /* If the Dark Mode preference is 'on', save preference, 
      update classes and set sessionStorage preference */
      if (document.getElementById('toggle-dark').classList.contains('on')) {
        document.documentElement.classList.remove('dark');
        document.documentElement.classList.add('light');
        document.getElementById('toggle-dark').classList.remove('on');
        document.getElementById('toggle-dark').classList.add('off');
        /* save user preference for this session */
        sessionStorage.prefersColorScheme = 'light';
      } else {
        /* If the Dark Mode preference is 'off', save preference, 
        update classes and set sessionStorage preference */
        document.documentElement.classList.add('dark');
        document.documentElement.classList.remove('light');
        document.getElementById('toggle-dark').classList.add('on');
        document.getElementById('toggle-dark').classList.remove('off');
        /* save user preference for this session */
        sessionStorage.prefersColorScheme = 'dark';
      }
      e.preventDefault();
    });
  }
  /* If the Rese Preference is clicked, reset preference variable, 
  remove classes and leave in default state */
  if (document.getElementById('toggle-dark-reset')) {
    document.getElementById('toggle-dark-reset').addEventListener('click', function(e) {
      document.documentElement.classList.remove('dark');
      document.documentElement.classList.remove('light');
      document.getElementById('toggle-dark').classList.remove('on');
      document.getElementById('toggle-dark').classList.remove('off');
      sessionStorage.prefersColorScheme = 'unset';
      e.preventDefault();

    });
                                                            
  }

}

/* On load, check for the session variable and set UI variables
accordingly */
window.onload = function() {
  if (sessionStorage.prefersColorScheme == 'dark' ) {
    document.documentElement.classList.add("dark");
    document.documentElement.classList.remove("light");
    document.getElementById('toggle-dark').classList.add('on');
  }
  if (sessionStorage.prefersColorScheme == 'light' ) {
    document.documentElement.classList.add("light");
    document.documentElement.classList.remove("dark");
    document.getElementById('toggle-dark').classList.add('off');
  }
};


              
            
!
999px

Console