Bootstrap CSS Forms Reference

Bootstrap’s Default Settings

Individual form controls automatically receive some global styling with Bootstrap.

All textual <input>, <textarea>, and <select> elements with class=”form-control” are set to width: 100%; by default.

Standard rules for all three form layouts:

  • Wrap labels and form controls in <div class="form-group"> (needed for optimum spacing)
  • Add class .form-control to all textual <input>, <textarea>, and <select> elements

The following example creates a simple Bootstrap form with two input fields, one checkbox, and a submit button:

Bootstrap Form Example

<form>
<div class=”form-group”>
<label for=”email”>Email address:</label>
<input type=”email” class=”form-control” id=”email”>
</div>
<div class=”form-group”>
<label for=”pwd”>Password:</label>
<input type=”password” class=”form-control” id=”pwd”>
</div>
<div class=”checkbox”>
<label><input type=”checkbox”> Remember me</label>
</div>
<button type=”submit” class=”btn btn-default”>Submit</button>
</form>

 


<form> Classes

Class Description Example
.form-inline Makes a <form> left-aligned with inline-block controls (This only applies to forms within viewports that are at least 768px wide)
.form-horizontal Aligns labels and groups of form controls in a horizontal layout

Leave a Reply

Your email address will not be published. Required fields are marked *