Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container my-5">
  
<h3>Bootstrap 4 HTML5 form validation demo</h3>
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/checkValidity">Learn more about form validation via MDN </a></p>
  <p><a href="http://getbootstrap.com/docs/4.1/components/forms/#validation">Bootstrap 4 form validation class documentation </a></p>
  
  
<hr>

  <div class="card bg-light">
<form class="card-body" novalidate="" action="" method="" id="bootstrapForm">
  
    <div class="form-group">
        <label class="h4 form-control-label" for="input1">Company name<abbr class="text-danger" title="This is required">*</abbr></label>
        <input type="text" class="form-control" name="i1" id="input1" required>
        <div class="valid-feedback">Company name looks good</div>
        <div class="invalid-feedback">Please enter your company name. This field is required</div>
    </div>
  
  
    <div class="form-group">
        <label class="h4 form-control-label" for="input1">Phone<abbr class="text-danger" title="This is required">*</abbr></label>
        <input type="tel" placeholder="123-456-7890"
           pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" class="form-control" name="i1" id="input1" required>
        <div class="valid-feedback">Phone # looks good</div>
        <div class="invalid-feedback">Please enter a phone # like 123-456-7890. This field is required.</div>
    </div>
  
    <div class="form-group">
        <label class="h4 form-control-label" for="input3">Website<abbr class="text-danger" title="This is required">*</abbr></label>
        <input type="url" placeholder="https://" class="form-control" name="i3" id="input3" required>
        <div class="valid-feedback">Website looks good.</div>
        <div class="invalid-feedback">Please enter a valid URL. This field is required.</div>
    </div>

  
  
    <div>
        <button type="submit" class="btn btn-secondary">Send Form</button>
    </div>  
  
</form>


</div>
<!-- /.card -->

</div>
<!-- /.container -->


            
          
!
            
              .form-valid  {
  opacity:0.5;
}

.form-control-label abbr {
  text-decoration: none;
  font-weight: normal;
}
            
          
!
            
              // adapted from https://www.codeply.com/go/mhkMGnGgZo/bootstrap-4-validation-example

$("#bootstrapForm").submit(function(event) {

    // make selected form variable
    var vForm = $(this);
    
  /*
  If not valid prevent form submit
  https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement/checkValidity
  */
    if (vForm[0].checkValidity() === false) {
      event.preventDefault()
      event.stopPropagation()
    } else {
     
      // Replace alert with ajax submit here...
      alert("your form is valid and ready to send");
      
    }
    
    // Add bootstrap 4 was-validated classes to trigger validation messages
    vForm.addClass('was-validated');
    
 
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console