BS5 Forms

In Bootstrap 5, the Form component provides a comprehensive set of classes and styles to create stylish and responsive forms. It offers various form controls, layout options, validation styles, and form customization features. Here's an overview of how to use the Form component in Bootstrap 5:


1. Basic Form Structure:

Start by wrapping your form elements within a `<form>` tag. Apply the `needs-validation` class to enable form validation. For example:

html
<form class="needs-validation" novalidate>
    <!-- Form controls go here -->
</form>

2. Form Controls:

Bootstrap 5 provides a range of form control classes for different input types. Some commonly used form controls are:

- Text Input: Use `<input type="text">` with the class `form-control`.
- Select Dropdown: Use `<select>` with the class `form-select`.
- Textarea: Use `<textarea>` with the class `form-control`.
- Checkbox: Use `<input type="checkbox">` with the class `form-check-input`.
- Radio Button: Use `<input type="radio">` with the class `form-check-input`.

For example, to create a text input and a select dropdown, use the following code:

html
<div class="mb-3">
    <label for="name" class="form-label">Name</label>
    <input type="text" class="form-control" id="name" required>
</div>

<div class="mb-3">
    <label for="gender" class="form-label">Gender</label>
    <select class="form-select" id="gender" required>
        <option value="">Select</option>
        <option value="male">Male</option>
        <option value="female">Female</option>
    </select>
</div>

Bootstrap 5 provides layout classes to control the arrangement of form elements. Some commonly used layout classes are:

- `.row`: Creates a row to contain form elements.
- `.col-*`: Defines the column width of form elements within a row. For example, `.col-6` makes the element take up half of the row width.

Use these layout classes to structure your form elements into rows and columns.

For example:

html
<div class="row">
    <div class="col-6">
        <!-- First column -->
    </div>
    <div class="col-6">
        <!-- First column -->
    </div>
</div>


About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext