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

              
                <button type="button" data-toggle-target="#myTogglingElement" data-toggle-class="blue">Toggle</button>

<div id="myTogglingElement">
  This element is targeted by ID and will have the <code>.blue</code> class toggled on it.</div>

<hr>

<button type="button" data-toggle-target=".multi-toggle" data-toggle-class="green">Toggle 2</button>

<div class="multi-toggle">
  This second element is targeted by class and will have the <code>.green</code> class toggled on it.</div>

<div class="multi-toggle">
  This third element is targeted by class and will also have the <code>.green</code> class toggled on it.</div>

<hr>

<button type="button" data-toggle-target="[data-type=test]" data-toggle-class="purple">Toggle 3</button>

<div data-type="test">
  This element is targeted by data attribute and will have the <code>.purple</code> class toggled on it.</div>
              
            
!

CSS

              
                body {
  padding: 1.5rem;
  margin: 0;
  font: 1rem/1.5 sans-serif;
}

button {
  display: inline-block;
  padding: 0.5rem 1rem;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  background-color: #fff;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 0.4rem;

  &:hover,
  &:focus {
    background-color: #f5f5f5;
  }
  &:active {
    background-color: #eee;
  }
}

.blue {
  color: royalblue;
}
.green {
  color: green;
}
.purple {
  color: purple;
}

hr {
  margin-block: 1.5rem;
}

div {
  position: relative;
  padding: 0.5rem;
  margin-block: 0.5rem;
  border-left: 0.25rem solid;

  &::after {
    position: absolute;
    inset: 0;
    display: block;
    content: "";
    background-color: currentColor;
    opacity: 0.05;
  }
}

              
            
!

JS

              
                let toggler = document.querySelectorAll("[data-toggle-target]")

if (toggler) {
  toggler.forEach(function (element) {
    let target = element.getAttribute("data-toggle-target")
    let targets = document.querySelectorAll(target)
    let toggleClass = element.getAttribute("data-toggle-class")

    element.addEventListener("click", (event) => {
      targets.forEach(function (e) {
        e.classList.toggle(toggleClass)
      })
    })
  })
}

              
            
!
999px

Console