Master Bootstrap From Scratch

Clear, interactive, and structured Bootstrap lessons designed for beginners and developers.

Bootstrap Custom Forms

Bootstrap provides useful classes for creating customized, responsive and user-friendly form controls.

Simple Explanation: Custom forms allow us to improve the appearance and usability of normal HTML form controls such as checkboxes, radio buttons, switches, range inputs and file inputs.

What are Custom Forms?

HTML provides basic form controls such as input boxes, checkboxes, radio buttons and dropdowns.

Bootstrap provides additional classes that make these controls visually consistent and responsive.

Custom form controls can be used for:

  • Registration forms
  • Student enquiry forms
  • Login pages
  • Course selection forms
  • Settings pages
  • User preference forms

Custom Checkbox

Bootstrap provides the .form-check, .form-check-input and .form-check-label classes for styling checkbox controls.

Example

<div class="form-check">

    <input class="form-check-input"
           type="checkbox"
           id="courseCheck">

    <label class="form-check-label"
           for="courseCheck">

        I want to join the course

    </label>

</div>

Output

Custom Radio Buttons

Radio buttons are used when the user must select only one option from a group.

All radio buttons belonging to the same group should use the same name attribute.

Example

<div class="form-check">

    <input class="form-check-input"
           type="radio"
           name="mode"
           id="online">

    <label class="form-check-label"
           for="online">

        Online

    </label>

</div>

<div class="form-check">

    <input class="form-check-input"
           type="radio"
           name="mode"
           id="offline">

    <label class="form-check-label"
           for="offline">

        Offline

    </label>

</div>

Output

Inline Checkboxes

The .form-check-inline class displays multiple checkbox or radio controls on the same line.

Example

<div class="form-check form-check-inline">

    <input class="form-check-input"
           type="checkbox"
           id="htmlCheck">

    <label class="form-check-label"
           for="htmlCheck">

        HTML

    </label>

</div>

<div class="form-check form-check-inline">

    <input class="form-check-input"
           type="checkbox"
           id="cssCheck">

    <label class="form-check-label"
           for="cssCheck">

        CSS

    </label>

</div>

Output

Inline Radio Buttons

The same .form-check-inline class can be used with radio buttons.

Example

<div class="form-check form-check-inline">

    <input class="form-check-input"
           type="radio"
           name="gender"
           id="male">

    <label class="form-check-label"
           for="male">

        Male

    </label>

</div>

<div class="form-check form-check-inline">

    <input class="form-check-input"
           type="radio"
           name="gender"
           id="female">

    <label class="form-check-label"
           for="female">

        Female

    </label>

</div>

Output

Switch

A switch provides a simple ON/OFF style interface. Bootstrap uses the .form-switch class for this purpose.

Example

<div class="form-check form-switch">

    <input class="form-check-input"
           type="checkbox"
           id="notificationSwitch">

    <label class="form-check-label"
           for="notificationSwitch">

        Enable Notifications

    </label>

</div>

Output

Multiple Switches

Multiple switches can be used to manage different independent settings.

Example

<div class="form-check form-switch">

    <input class="form-check-input"
           type="checkbox">

    <label class="form-check-label">
        Email Notifications
    </label>

</div>

<div class="form-check form-switch">

    <input class="form-check-input"
           type="checkbox">

    <label class="form-check-label">
        SMS Notifications
    </label>

</div>

Output

Range Input

A range input allows users to select a numeric value by moving a slider.

Bootstrap uses the .form-range class.

Example

<label class="form-label">
    Experience
</label>

<input type="range"
       class="form-range"
       min="0"
       max="10">

Output

Range with Step

The step attribute controls the increments of the range input.

Example

<input type="range"
       class="form-range"
       min="0"
       max="100"
       step="10">

Output

0 10 20 30 40 50 60 70 80 90 100

File Input

Bootstrap can style a file upload control using the .form-control class.

Example

<label class="form-label">
    Upload Resume
</label>

<input type="file"
       class="form-control">

Output

Color Input

HTML provides a color input that allows users to select a color.

Example

<label class="form-label">
    Select Color
</label>

<input type="color"
       class="form-control form-control-color"
       value="#0d6efd">

Output

Form Control with Help Text

The .form-text class can be used to display additional information below a form control.

Example

<label class="form-label">
    Password
</label>

<input type="password"
       class="form-control">

<div class="form-text">

    Password must contain at least 8 characters.

</div>

Output

Password must contain at least 8 characters.

Custom Select

The .form-select class provides Bootstrap styling for select controls.

Example

<label class="form-label">
    Select Technology
</label>

<select class="form-select">

    <option>
        Select Technology
    </option>

    <option>
        .NET
    </option>

    <option>
        Java
    </option>

    <option>
        Python
    </option>

</select>

Output

CIIT Training Institute Example

Let's create a simple course preference form for CIIT Training Institute using different Bootstrap custom form controls.

Important Custom Form Classes

Class Purpose
.form-check Container for checkbox or radio
.form-check-input Styles checkbox/radio input
.form-check-label Styles checkbox/radio label
.form-check-inline Displays controls inline
.form-switch Creates a switch-style checkbox
.form-range Styles range sliders
.form-select Styles select controls
.form-control-color Styles color input controls
.form-text Displays additional help text

Common Mistakes

  • Forgetting to connect the label's for attribute with the input's id.
  • Giving different name values to radio buttons that should behave as one group.
  • Using .form-switch without .form-check.
  • Using .form-range on a normal text input.
  • Using too many custom controls on a single form, making the form difficult to understand.

Summary

  • Bootstrap provides classes for creating customized and responsive form controls.
  • .form-check is used for checkbox and radio controls.
  • .form-check-inline displays controls horizontally.
  • .form-switch creates ON/OFF style switches.
  • .form-range creates a styled range slider.
  • .form-select styles dropdown controls.
  • .form-text provides additional help information.
  • Custom forms improve the usability and appearance of registration, enquiry and application forms.