Lesson 23 of 60 – Bootstrap Form Controls
38%

Bootstrap Form Controls

Bootstrap provides several classes for styling and controlling HTML form elements such as text inputs, passwords, email fields, textareas, select boxes, checkboxes, radio buttons, range inputs, and file inputs. These controls help you create clean, consistent, and responsive forms.

Note: Bootstrap form controls are still standard HTML elements. Bootstrap mainly provides CSS classes that improve their appearance and layout.

1. What Are Form Controls?

Form controls are the elements through which users enter or select information in an HTML form.

Common form controls include:

  • Text input
  • Email input
  • Password input
  • Number input
  • Date input
  • Textarea
  • Select dropdown
  • Checkbox
  • Radio button
  • File input
  • Range input

Bootstrap provides classes to make these controls visually consistent.

2. Text Input Control

A text input is used to collect short text such as a name, username, city, or subject.

<input type="text"
class="form-control"
placeholder="Enter your name">

3. Email Control

The email input is used for collecting email addresses.

<input type="email"
class="form-control"
placeholder="name@example.com">

The email input type also allows browsers to provide appropriate input behavior and basic validation.

4. Password Control

Password fields hide the characters entered by the user.

<input type="password"
class="form-control"
placeholder="Enter password">
Important: A password input only hides characters visually. Secure password storage and authentication must be handled by the server-side application.

5. Number Control

The number input is useful for numeric values such as age, quantity, marks, or price.

<input type="number"
class="form-control"
placeholder="Enter age">

6. Minimum and Maximum Values

The min and max attributes can define the allowed numeric range.

<input type="number"
class="form-control"
min="1"
max="100">

These HTML attributes provide client-side constraints. Server-side validation should also be performed when processing submitted data.

7. Step Attribute

The step attribute controls the allowed increments for numeric inputs.

<input type="number"
class="form-control"
step="5">

For example, a step of 5 allows values such as 0, 5, 10, 15, and so on when the browser applies the constraint.

8. Date Control

The date input allows users to select a calendar date.

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

9. Time Control

The time input allows users to select a time.

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

10. Date and Time Controls

HTML provides different date and time input types. For example, datetime-local allows users to enter a local date and time.

<input type="datetime-local"
class="form-control">

11. Textarea Control

A textarea is used when users need to enter multiple lines of text.

<textarea
class="form-control"
rows="4"
placeholder="Enter address">
</textarea>

12. Select Control

The .form-select class styles a standard HTML <select> element.

<select class="form-select">

    <option selected>
    Select Course
    </option>

    <option>
    HTML
    </option>

    <option>
    CSS
    </option>

</select>

13. Multiple Select

The HTML multiple attribute allows users to select multiple options from a select control.

<select class="form-select"
multiple>

    <option>HTML</option>
    <option>CSS</option>
    <option>JavaScript</option>
    <option>Python</option>

</select>

On a desktop browser, multiple options can generally be selected using the operating system's standard multi-selection behavior.

14. Checkbox Control

Checkboxes are useful when users can select one or more independent options.

<div class="form-check">

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

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

    HTML

    </label>

</div>

15. Radio Button Control

Radio buttons are used when the user should choose one option from a group.

<div class="form-check">

    <input
    class="form-check-input"
    type="radio"
    name="course"
    id="htmlCourse">

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

    HTML

    </label>

</div>

16. Range Control

The range input creates a slider that allows users to choose a value from a specified range.

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

Bootstrap uses the .form-range class to style range inputs.

17. Range with Step

The step attribute can control how the range value changes.

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

18. File Control

The form-control class can be used to style a file input.

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

The browser provides the file-selection interface. Uploading and storing the selected file requires server-side processing.

19. Color Control

The HTML color input can be styled with the .form-control-color class.

<input type="color"
class="form-control form-control-color"
value="#563d7c">

20. Input Size Controls

Bootstrap provides large and small sizes for many text-based form controls.

<input
class="form-control form-control-lg"
placeholder="Large input">

<input
class="form-control"
placeholder="Normal input">

<input
class="form-control form-control-sm"
placeholder="Small input">

21. Disabled Controls

The disabled attribute prevents the user from interacting with a control.

<input
type="text"
class="form-control"
value="Disabled Field"
disabled>

22. Readonly Controls

The readonly attribute prevents users from editing the value of a text-based control.

<input
type="text"
class="form-control"
value="STU-101"
readonly>

Readonly and disabled are different. A disabled control cannot be interacted with, while a readonly text control can generally still be focused and its value is submitted with the form.

23. Placeholder

The placeholder attribute displays a short hint inside an empty form control.

<input
type="text"
class="form-control"
placeholder="Enter your name">
Remember: A placeholder is a hint, not a replacement for a visible label.

24. Required Controls

The required attribute tells the browser that a value must be provided before the form can be submitted.

<input
type="text"
class="form-control"
required>

25. Form Help Text

The .form-text class provides additional information about a form control.

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

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

<div class="form-text">
Password should be kept private.
</div>
Never share your password with other people.

26. Input Group with Form Control

An input group can combine a form control with text or other elements.

<div class="input-group">

    <span class="input-group-text">
    ₹
    </span>

    <input
    type="number"
    class="form-control"
    placeholder="Amount">

</div>
₹

27. Validation Controls

Bootstrap provides validation classes for displaying valid and invalid states.

<input
class="form-control is-valid"
value="Correct value">

<input
class="form-control is-invalid"
value="">

<div class="valid-feedback">
Looks good!
</div>

<div class="invalid-feedback">
Please enter a value.
</div>
Looks good!
Please enter a valid value.

28. Responsive Form Controls

Bootstrap form controls can be combined with the grid system to create responsive layouts.

<div class="row">

    <div class="col-md-6 mb-3">

        <label class="form-label">
        First Name
        </label>

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

    </div>

    <div class="col-md-6 mb-3">

        <label class="form-label">
        Last Name
        </label>

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

    </div>

</div>

On smaller screens, the columns can stack because of Bootstrap's responsive grid behavior.

29. Practical Student Form Controls

The following example combines different Bootstrap form controls commonly used in a student admission form.

30. Complete Form Controls Example

This example combines several Bootstrap form controls into one responsive form.

<form>

    <div class="row">

        <div class="col-md-6 mb-3">

            <label class="form-label">
            Full Name
            </label>

            <input
            type="text"
            class="form-control"
            placeholder="Enter full name"
            required>

        </div>


        <div class="col-md-6 mb-3">

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

            <input
            type="email"
            class="form-control"
            placeholder="Enter email"
            required>

        </div>


        <div class="col-md-6 mb-3">

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

            <input
            type="number"
            class="form-control"
            min="1"
            max="100">

        </div>


        <div class="col-md-6 mb-3">

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

            <select class="form-select">

                <option selected>
                Select Course
                </option>

                <option>
                HTML
                </option>

                <option>
                CSS
                </option>

                <option>
                Python
                </option>

            </select>

        </div>


        <div class="col-12 mb-3">

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

            <textarea
            class="form-control"
            rows="4">
            </textarea>

        </div>


        <div class="col-12 mb-3">

            <div class="form-check">

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

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

                I agree to the terms.

                </label>

            </div>

        </div>


        <div class="col-12">

            <button
            type="submit"
            class="btn btn-primary">

            Submit

            </button>

            <button
            type="reset"
            class="btn btn-secondary">

            Reset

            </button>

        </div>

    </div>

</form>

📌 Key Points

  • Bootstrap form controls are based on standard HTML form elements.
  • Use .form-control for many text-based inputs.
  • Use .form-select for select controls.
  • Use .form-check for checkboxes and radio buttons.
  • Use .form-range for range sliders.
  • Use .form-control-color for color inputs.
  • Use .form-control-lg and .form-control-sm for input sizing.
  • Use disabled to prevent interaction with a control.
  • Use readonly when a text value should not be edited.
  • Use required for required fields.
  • Use min, max, and step where appropriate for numeric controls.
  • Use .form-text for helpful instructions.
  • Use .is-valid and .is-invalid for validation states.
  • Use Bootstrap grid classes to make form controls responsive.
  • Always use meaningful labels for form controls.

🧠 Quick Quiz

Question: Which Bootstrap class is used to style a standard select dropdown?