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

              
                <form>
  <div class="form-row">
    <label for="prefixed-input">Prefixed</label>
    <div class="input" data-prefix="$">
      <input id="prefixed-input">
    </div>
  </div>
  <div class="form-row">
    <label for="suffixed-input">Suffixed</label>
    <div class="input" data-suffix="months">
      <input id="suffixed-input">
    </div>
  </div>
  <div class="form-row">
    <label for="both-input">Prefixed AND Suffixed!</label>
    <div class="input" data-prefix="$" data-suffix="/lb">
      <input id="both-input">
    </div>
  </div>
  <div class="form-row">
    <label for="none-input">No prefix or suffix</label>
    <div class="input">
      <input id="none-input">
    </div>
  </div>
</form>
              
            
!

CSS

              
                $input-height:35px;

html,body {
  font-family:"Helvetica Neue","Helvetica","Arial",sans-serif;
}

*,:before,:after,input {
  box-sizing:border-box;
  font-size:14px;
}

input {
  height:$input-height;
  width:100%;
  border-radius:2px;
  border:1px solid lighten(black,80);
  outline:none;
  padding:0 10px;
}

form {
  width:375px;
  margin:100px auto;
  .form-row {
    display:flex;
    align-items:center;
    padding:10px;
    label {
      flex-grow:1;
      padding-right:10px;
    }
    .input {
      max-width:150px;
      width:150px;
      &.focus {
        *,&:before,&:after {
          border-color:#00A7E1;
        }
        &:before,&:after {
          color:#00A7E1;
        }
      }
    }
  }
}

[data-prefix],[data-suffix]{
  position:relative;
  display:flex;
  align-items:center;
  flex-grow:0;
  input {
    flex-shrink:1;
    flex-grow:1;
  }
  &:before,&:after {
    height:$input-height;
    line-height:$input-height - 2;
    color:lighten(black,60);
  }
}

[data-prefix]{
  &:before {
    content:attr(data-prefix);
    display:block;
    padding:0 0 0 10px;
    border-top:1px solid lighten(black,80);
    border-left:1px solid lighten(black,80);
    border-bottom:1px solid lighten(black,80);
    border-top-left-radius:2px;
    border-bottom-left-radius:2px;
  }
  input {
    border-left:none;
    padding-left:5px;
    border-top-left-radius:0;
    border-bottom-left-radius:0;
  }
}

[data-suffix]{
  &:after {
    content:attr(data-suffix);
    display:block;
    padding:0 10px 0 0;
    border-top:1px solid lighten(black,80);
    border-right:1px solid lighten(black,80);
    border-bottom:1px solid lighten(black,80);
    border-radius:0 2px 2px 0;
  }
  input {
    border-right:none;
    padding-right:5px;
    border-top-right-radius:0;
    border-bottom-right-radius:0;
  }
}
              
            
!

JS

              
                /**
* Walk up DOM tree to get parent element with the matching class
* @param {Element} Element to search from
* @param {string} The class name to identify target parent
* @return {Element} The parent element with targetClass or null of we reach the top of the DOM tree
**/
function getTargetParent(elem, targetClass) {
    var currElem = elem;
    while(
  	  currElem
  	  && !currElem.classList.contains(targetClass)
    ) {
    	currElem = currElem.parentNode;
    }
    return currElem;
}

/**
* Add a focus event listener to an element to add "focus" class on the parent identified by targetClass
**/
function addFocusListener(elem, targetClass) {
  var targetParent = getTargetParent(elem, targetClass);
  if(targetParent) {
		elem.addEventListener('focus', function() {
	    targetParent.classList.add('focus');
    });
    elem.addEventListener('blur', function() {
    	targetParent.classList.remove('focus');
    });
  }
}

var inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
	addFocusListener(inputs[i], 'input');
}
              
            
!
999px

Console