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 class="bg-black">
  <form id="form" action="#" autocomplete="off">
    <label for="theme-color">Set Theme Color</label>
    <select name="theme-color" id="theme-color" class="bg-black">
      <option value="#fff">White</option>
      <option value="#0074d9">Blue</option>
      <option value="#7fdbff">Aqua</option>
      <option value="#39cccc">Teal</option>
      <option value="#b10dc9">Purple</option>
      <option value="#f012be">Fuchsia</option>
      <option value="#ff4136">Red</option>
      <option value="#ff851b">Orange</option>
      <option value="#ffdc00">Yellow</option>
      <option value="#3d9970">Olive</option>
      <option value="#2ecc40">Green</option>
      <option value="#01ff70">Lime</option>
    </select>
    <button class="submit black">Submit</button>
  </form>
  <button type="button" id="forget" class="forget">Forget my choice</button>
</div>
              
            
!

CSS

              
                :root {
  --theme-setting-color: #fff;
}

html {
  height: 100%;
}

body {
  align-items: center;
  display: flex;
  height: 100%;
  justify-content: center;
  text-align: center;
}

div {
  color: var(--theme-setting-color);
  align-items: center;
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: center;
  width: 100%;
}

form {
  display: flex;
  flex-direction: column;
}

label {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  margin-bottom: 1em;
}

select {
  appearance: none;
  border: 2px solid var(--theme-setting-color);
  border-radius: 0.25em;
  display: block;
  font-size: 1.25rem;
  padding: 0.5em;
  min-width: 20em;
  color: var(--theme-setting-color);
  
  &:hover,
  &:focus {
    box-shadow: 0 0 0.5em var(--theme-setting-color);
  }
}

.submit {
  background-color: var(--theme-setting-color);
  border: 2px solid var(--theme-setting-color);
  border-radius: 0.25em;
  font-size: 1.25rem;
  padding: 0.5em;
  margin-top: 1em;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  
  &:hover,
  &:focus {
    box-shadow: 0 0 0.5em var(--theme-setting-color);
  }
}

.forget {
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  color: var(--theme-setting-color);
  margin-top: 1em;
  
  &:hover,
  &:focus {
    text-decoration: underline;
  }
}
              
            
!

JS

              
                const form = document.getElementById('form');
const select = document.getElementById('theme-color');
const key = 'theme-setting-color';
const stored = localStorage.getItem(key);
const forget = document.getElementById('forget');

// Handle the submit
form.addEventListener('submit', (event) => {
  // No actual submit
  event.preventDefault();
  
  // Get the color
  const color = select.value;

  // Set the color on the doc
  document.documentElement.style.setProperty(`--${key}`, color);
  
  // Set in local storage
  localStorage.setItem(key, color);
});

// Forget
forget.addEventListener('click', () => {
  // remove from storage
  localStorage.removeItem(key);
  
  // Reset
  select.value = '#fff';
  
  // Set the color on the doc
  document.documentElement.style.setProperty(`--${key}`, '#fff');
});


if ( '' !== stored ) {
  // Set value in select
  select.value = stored;
  
  // Set the color on the doc
  document.documentElement.style.setProperty(`--${key}`, stored);
} 
              
            
!
999px

Console