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="c-form-area js-form-area">
  <h1 class="c-type-alpha">Login</h1>
  <form>
    <input class="c-input js-input" type="text" placeholder="Username">
    <input class="c-input js-input" type="password" placeholder="Password">
    <button class="c-button" data-class="is-loading, is-disabled" data-class-element="js-form-area, js-input" data-class-scope="false, js-form-area">Submit</button>
  </form>
</div>
              
            
!

CSS

              
                body {
  font-family:sans-serif;
  background-color:#f4f4f4;
}

.c-form-area {
  width:300px;
  background-color:#ffffff;
  border:1px solid #cccccc;
  border-radius:3px;
  padding:10px 10px 20px 10px;
  margin:30px auto;
  box-shadow: 1px 1px 5px rgba(0,0,0,0.2);
}

.c-input {
  display:block;
  width:100%;
  margin-bottom:20px;
  font-size:inherit;
  padding:10px;
  box-sizing:border-box;
}

.c-input.is-disabled {
  background:#ccc;
  pointer-events:none;
	user-select:none;
  border:0;
}

.c-type-alpha {
  text-align:center;
}

.c-button {
  display:block;
  margin:0 auto;
  font-size:inherit;
  padding:10px;
}

.c-form-area.is-loading {
  position:relative;
  &:before {
    position:absolute;
    top:0;
    left:0;
    display:block;
    content:"";
    width:100%;
    height:100%;
    background:rgba(255,255,255,0.9);
  }
  &:after {
    height:20px;
    text-align:center;
    display:block;
    content:"Loading...";
    position:absolute;
    margin:auto;
    left:0;
    right:0;
    top:0;
    bottom:0;
  }
}
              
            
!

JS

              
                // Grab all elements with data-active attribute
var elems = document.querySelectorAll("[data-class][data-class-element]");

// closestParent helper function
closestParent = function(child, match) {
	if (!child || child == document) {
		return null;
	}
	if (child.classList.contains(match) || child.nodeName.toLowerCase() == match) {
		return child;
	}
	else {
		return closestParent(child.parentNode, match);
	}
}

// Loop through if any are found
for(var i = 0; i < elems.length; i++){
	// Add event listeners to each one
	elems[i].addEventListener("click", function(e){

		// Prevent default action of element
		e.preventDefault();

		// Grab classes list and convert to array
		var dataClass = this.getAttribute('data-class');
		dataClass = dataClass.split(", ");

		// Grab linked elements list and convert to array
		var dataClassElement = this.getAttribute('data-class-element');
		dataClassElement = dataClassElement.split(", ");

		// Grab data-scope list if present and convert to array
		if(this.getAttribute("data-class-scope")) {
			var dataClassScope = this.getAttribute("data-class-scope");
			dataClassScope = dataClassScope.split(", ");
		}

		// Loop through all our dataClassElement items
		for(var b = 0; b < dataClassElement.length; b++) {
			// Grab elem references, apply scope if found
			if(dataClassScope && dataClassScope[b] !== "false") {
				// Grab parent
				var elemParent = closestParent(this, dataClassScope[b]),

				// Grab all matching child elements of parent
				elemRef = elemParent.querySelectorAll("." + dataClassElement[b]);

				// Convert to array
				elemRef = Array.prototype.slice.call(elemRef);

				// Add parent if it matches the data-class-element and fits within scope
				if(dataClassScope[b] === dataClassElement[b] && elemParent.classList.contains(dataClassElement[b])) {
					elemRef.unshift(elemParent);
				}
			}
			else {
				var elemRef = document.querySelectorAll("." + dataClassElement[b]);
			}
			// Grab class we will add
			var elemClass = dataClass[b];
			// Do
			for(var c = 0; c < elemRef.length; c++) {
				elemRef[c].classList.toggle(elemClass);
			}
		}

	});    
}
              
            
!
999px

Console