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 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

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 class="wrapper">
<div class="main">
<form>
  <fieldset>
  <select name="setting">
    <option value="-1" selected>System Settings</option>
    <option value="0">Dark Mode</option>
    <option value="1">Light Mode</option>
  </select>
  <button type="reset">Reset</button>
  <button type="submit">Apply</button>
    <div class="info-box">
      <span class="light-info">light</span>
      <span class="dark-info">dark</span>
    </div>
  </fieldset>
</form>
<div class="demo">
  <div class="content">
  <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec.</p>
</div>
  </div>
</div>
</div>
              
            
!

CSS

              
                // common settings
body {
  font-family: sans-serif;
  line-height: 1.6;
  font-size: 16px;
}

.main {
  display: flex;
  flex-direction: column;
  align-item: center;
  min-height: 100vh;
}

form {
  flex-shrink: 0;
  padding: 1rem;
  left: 0;
  right: 0;
  margin: 0 auto;
  fieldset {
    width: max-content;
    margin: 0 auto;
  }
}

select {
  background-color: white;
  padding: 0.5rem;
  margin: 0.5rem;
  border-radius: 5px;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
  border: 1px solid #ccc;
}

button {
  padding: 0.5rem;
  margin: 0.5rem;
  border-radius: 5px;
  background-color: #555;
  color: white;
  border: 1px solid #555;

  &[type="reset"] {
    background-color: darkred;
    border-color: darkred;
  }
  &[type="submit"] {
    background-color: darkgreen;
    border-color: darkgreen;
    position: absolute;
    
    // stolen from tailwindcss
    // @see https://tailwindcss.com/docs/screen-readers#class-reference
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }
}

.info-box {
  margin-top: 0.5rem;
  text-align: center;
}

.demo {
  max-width: 720px;
  margin: 1rem auto;
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}
.content {
  padding: 1rem;
}

// mixin light mode
@mixin light {
  .main {
    background-color: white;
    color: #333;
  }

  form {
    background-color: #eee;
  }

  .content {
    border: 1px solid black;
  }

  .dark-info {
    display: none;
  }

  .light-info {
    display: inherit;
  }
}

// mixin dark mode
@mixin dark {
  .main {
    background-color: black;
    color: #ccc;
  }

  form {
    background-color: #222;
  }

  .content {
    border: 1px solid white;
  }

  .light-info {
    display: none;
  }

  .dark-info {
    display: inherit;
  }
}

// default light
@include light;

// dark mode depending on preferences
@media (prefers-color-scheme: dark) {
  @include dark;
}

// override preferences if dark mode is explicitly set
.dark {
  @include dark;
  @media (prefers-color-schema: light) {
    @include dark;
  }
}

// light mode depending on preferences
@media (prefers-color-scheme: light) {
  @include light;
}

// override preferences if light mode is explicitly set
.light {
  @include light;
  @media (prefers-color-schema: dark) {
    @include light;
  }
}

              
            
!

JS

              
                (function () {
  const wrapper = document.querySelector(".wrapper")
  const form = document.querySelector("form");
  const settingField = document.querySelector("[name='setting']");
  
  function handleSubmit(ev) {
    ev.preventDefault();
    applySettings();
  }
  
  function handleReset(ev) {
    ev.preventDefault();
    settingField.value = "-1"
    applySettings()
  }

  function applySettings() {
    const value = parseInt(settingField.value)
    wrapper.classList.remove("dark","light");
    if (value === 0) {
      wrapper.classList.add("dark")
    } else if (value === 1) {
      wrapper.classList.add("light")
    }
  }

  form.addEventListener("submit", handleSubmit);
  form.addEventListener("reset", handleReset);
  settingField.addEventListener("change", applySettings);
  applySettings()
})();

              
            
!
999px

Console