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.


                <body class="bg-main text-main">
  <nav class="mx-auto my-6 max-w-2xl font-bold flex justify-between">
    <h1 class="text-2xl">Light/Dark</h1>
    <a id="toggle" class="relative my-1 w-6 h-6" href="#">
      <svg id="moon" class="absolute inset-0 w-6 h-6 theme-light" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" /></svg>
		  <svg id="sun" class="absolute inset-0 w-6 h-6 theme-dark" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5" /><path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42" /></svg>

  <div class="bg-panel mx-auto max-w-2xl p-5 my-6 rounded-lg">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore amet animi voluptas aperiam repellendus eos alias, perspiciatis saepe quas, deserunt ea unde commodi tempora et reiciendis recusandae sapiente libero impedit.</p>

  <div class="bg-panel mx-auto max-w-2xl p-5 my-6 rounded-lg">
    <div class="relative h-6">
      <p class="absolute inset-0 theme-light">This text appears in light mode</p>
      <p class="absolute inset-0 theme-dark">This text appears in dark mode</p>


                :root {
  --background-main: #f7fafc;
  --background-panel: #edf2f7;
  --text-main: #1a202c;
  --opacity-light: 1;
  --opacity-dark: 0;

[data-theme='dark'] {
  --background-main: #1a202c;
  --background-panel: #2d3748;
  --text-main: #f7fafc;
  --opacity-light: 0;
  --opacity-dark: 1;

.bg-main {
  background-color: var(--background-main);

.bg-panel {
  background-color: var(--background-panel);

.text-main {
  color: var(--text-main);

.theme-light {
  opacity: var(--opacity-light);

.theme-dark {
  opacity: var(--opacity-dark);

html.transition *,
html.transition *:before,
html.transition *:after {
  transition-property: background-color color opacity !important;
  transition-duration: 750ms !important;
  transition-delay: 0 !important;
  transition-timing-function: linear !important;



                window.addEventListener('DOMContentLoaded', function(event) {
  // Load the current theme from storage
  const currentTheme = localStorage.getItem('currentTheme') || 'light';
  // Set the theme attribute
  document.documentElement.setAttribute('data-theme', currentTheme);

document.getElementById('toggle').addEventListener('click', function(event) {
  // Get the current theme and calculate the new theme
  const currentTheme = localStorage.getItem('currentTheme') || 'light';
  const newTheme = currentTheme === 'light' ? 'dark' : 'light';

  // Store the theme in local storage
  localStorage.setItem('currentTheme', newTheme);

  // Temporarily set a transition style
  setTimeout(() => {
  }, 750);

  // Set the theme attribute
  document.documentElement.setAttribute('data-theme', newTheme);