How to customize an HTML form with Bootstrap 4
Overview
Bootstrap allows us to customize the appearance of our form. It allows us to style every HTML element involved in creating a form from the checkbox to the radio button and the input element. Let's see an example of a customized form.
Example
Explanation
- Lines 24–28: We explain the entire process of form customization.
- Line 24: Notice that all input fields have a wrapper
<div>with a class attribute ofform-group. This class is added to the field wrapper for styling around the<input>element.
- Line 26: We customize this
<input>element by adding the Bootstrap classform-controlto the<input>element with thetypeattribute oftext. The wrapper<div>ensures that the<label>and<input>elements are aligned well.
- Lines 29–32: We repeat the same thing by adding the same classes to the
<input>element.
- Line 34: We see that the
<input>element has a Bootstrap class ofform-check-inputto style it. We use a different class here because of thetypeattribute of this<input>element. This is acheckboxand nottextlike the initial two<input>elements. Lookup form customization for more classes to customize your form.
- Line 25: We see how we apply the
form-check-labelto the<label>element. This allows the checkbox and the text/label to align well in height and spacing.