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

              
                <!DOCTYPE html>
<html lang="en">
<head>
  <script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>User-Friendley Character Limit UI</title>
</head>
<body>
  
<div class="container">
    <h2>User-Friendly Character Limit UI (WIP)</h2>
    <p>This component is designed to show how to implement a character limit. Start typing and see what happens as you go over the limit.</p>
    
    <div class="characterLimit">
      <label for="message" class="p-b">Your Message:</label>
      <textarea id="message" class="message" name="message" contenteditable="true"></textarea>
      <div class="flex">
        <div>
          <label class="limit">Max 120 Characters</label>
        </div>
        <div>
          <span class="char-left"></span>
          <input type="submit" class="submit" value="Submit" />
        </div>
      </div>
    </div>
    
</div>
  
  
</body>
</html>
              
            
!

CSS

              
                html {
  font-size: 100%;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
}

*, *::before, *::after {
  -webkit-box-sizing: inherit;
          box-sizing: inherit;
}

body {
  margin: 0px;
  padding: 0px;
  line-height: 1.5;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px;
  background-color: #80DEFF;
  color: #353535;
}

.container {
  background-color: white;
  border-radius: 4px;
  max-width: 500px;
  margin: 4rem auto;
  padding: 1.25rem;
  width: 80%;
  -webkit-box-shadow: 1px 3px 10px rgba(0,0,0,.15);  /* Safari 3-4, iOS 4.0.2 - 4.2, Android 2.3+ */
  -moz-box-shadow:    1px 3px 10px rgba(0,0,0,.15); /* Firefox 3.5 - 3.6 */
  box-shadow:         1px 3px 10px rgba(0,0,0,.15);  /* Opera 10.5, IE 9, Firefox 4+, Chrome 6+, iOS 5 */
  
 }

.characterLimit {
  position:relative;
}
.characterLimit label {
  display: block;
}

.characterLimit textarea {
  resize: vertical;
  width: 100%;
  border-radius: 4px;
  border: 1px solid #ccc;
  padding: 1rem 0.5rem;
  min-height: 115px;
  margin-bottom: 0.25rem;
  font-family: Arial, Helvetica, sans-serif;
}
.characterLimit textarea:focus {
  box-shadow: 0 0 2pt 2pt lightblue;
  border-color: lightblue;
  outline: transparent;
  border-radius: 4px;
}

.flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.char-left {
  margin-right: .75rem;
}
.message.warning, .message.warning:focus {
   box-shadow: 0 0 2pt 2pt rgba(255, 0, 0, 0.5);
   border-color: red;
}
.warning {
  color:red;
}
.submit {
  background-color: #3DC08D;
  font-size: 18px;
  color:white;
  border: none;
  border-radius: 4px;
  padding: 0.7rem 1.25rem;
  transition: all 200ms ease-in-out;
}
.submit:hover {
  background-color: #008A5B;
  cursor:pointer;
}

.disable {
  pointer-events: none;
  opacity: 0.5;
}
.p-t {
  padding-top: .75rem;
}
.p-b {
  padding-bottom: .75rem;
}

              
            
!

JS

              
                (function(){
  var msg = document.getElementsByClassName("message")[0],
      charLeftLabel = "char-left",
      charLeft = document.getElementsByClassName(charLeftLabel)[0], 
      textareaLabel = "message",
      maxChar = 120,
      maxCharWarn = 0;
  var submitButton = document.getElementsByClassName("submit")[0],
      submitButtonLabel = "submit";
 
  
  	  // show characters left at start
  	  charLeft.innerHTML = maxChar;

  	  // update while typing
  	  msg.onkeydown = function(){
        setTimeout(function(){
          charLeft.innerHTML = maxChar - msg.value.length;

          // whether or not to display warning class based on characters left
          var warnLabel = msg.value.length >= maxChar ? " warning" : "";
          charLeft.className = charLeftLabel + warnLabel;
          
          var warningLabel = msg.value.length >= maxChar ? " warning" : "";
          msg.className = textareaLabel + warningLabel;
          
          var disableBtn = msg.value.length >= maxChar ? " disable" : "";
          submitButton.className = submitButtonLabel + disableBtn;
          console.log(submitButton);
          
        }, 1); 
      };
})();
              
            
!
999px

Console