Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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: "Roboto Delta VF";
  src: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/57225/RobotoDelta_v2-VF.woff2")
    format("woff2-variations");
  font-weight: 100 900;
  font-stretch: 75% 100%;
  font-style: normal;
  font-display: swap;
}

:root {
  --text-size: 1.25rem;
  --text-vf-wght: 400;  
  --text-vf-wdth: 100;
  --text-vf-GRAD: 0;

  --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: "Roboto Delta VF", Arial, sans-serif;
  font-size: var(--text-size);
  font-stretch: calc( var(--text-vf-wdth) * 1% );
  font-weight: var(--text-vf-wght);
  font-variation-settings: 'GRAD' var(--text-vf-GRAD);
}

h1 {
  font-family: "Roboto Delta 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);
  font-variation-settings: 'GRAD' var(--text-vf-GRAD);
}

@media (prefers-color-scheme:dark) {
  :root {
    /* flip the light and dark variables */
    --color-text: var(--color-light);
    --color-background: var(--color-dark);
    --text-vf-GRAD: 0.25;
  }
  p, 
  .dark p {
    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 {
    letter-spacing: 0.0125em;
  }
  .light p {
    --text-vf-GRAD: 0;
    letter-spacing: auto;
  }
}

.dark {
  /* flip the light and dark variables */
  --color-text: var(--color-light);
  --color-background: var(--color-dark);
  --text-vf-GRAD: 0.25;
}
.light {
  /* flip the light and dark variables */
  --color-text: var(--color-dark);
  --color-background: var(--color-light);
  letter-spacing: auto;
}
.dark p {
  letter-spacing: 0.0125em;
}
.light p {
  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: "Roboto Delta 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