Home Videos Exercises MCQ Q&A Quiz E-Store Services Blog Sign in Appointment Payment

Bootstrap Forms

Bootstrap Forms are a set of pre-designed, responsive form components provided by the Bootstrap framework. They are styled consistently and are mobile-friendly by default, making it easy to create visually appealing and functional forms without extensive custom styling.

Bootstrap forms use a combination of HTML elements, classes, and CSS to style inputs, labels, validation messages, and other form controls. Here’s a breakdown of some key components and customization options available with Bootstrap forms.


Stacked Form

All textual <input> and <textarea> elements with class .form-control get proper form styling:

Example:
<form action="/action_page.php">
<div class="mb-3 mt-3">
<label for="email" class="form-label">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="mb-3">
<label for="pwd" class="form-label">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pswd">
</div>
<div class="form-check mb-3">
<label class="form-check-label">
<input class="form-check-input" type="checkbox" name="remember"> Remember me </label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>


Form Row/Grid

If you want your form elements to appear side by side, use .row and .col:

Example:
<form>
<div class="row">
<div class="col">
<input type="text" class="form-control" placeholder="Enter email" name="email">
</div>
<div class="col">
<input type="password" class="form-control" placeholder="Enter password" name="pswd">
</div>
</div>
</form>


Form Control Size

You can change the size of .form-control inputs with .form-control-lg or .form-control-sm:

Example:
<input type="text" class="form-control form-control-lg" placeholder="Large input">
<input type="text" class="form-control" placeholder="Normal input">
<input type="text" class="form-control form-control-sm" placeholder="Small input">


Plain text Inputs

Use the .form-control-plaintext class to style an input field without borders, but keep proper marigins and padding:

Example:
<input type="text" class="form-control-plaintext" placeholder="Plaintext input">
<input type="text" class="form-control" placeholder="Normal input">


Color Pickerr

To style an input with type="color" properly, use the .form-control-color class:

Example:
<input type="color" class="form-control form-control-color" value="#CCCCCC">


Key points of Bootstrap Forms

Responsive Layouts:

Forms in Bootstrap are mobile-first, automatically adapting to different screen sizes, with options for inline, horizontal, and vertical layouts.


Consistent Styling:

The form-control class provides consistent styling for input fields, dropdowns, text areas, and other controls, making them uniform across the form.


Grid-Based Form Layouts:

Bootstrap’s grid system enables creating multi-column form layouts, offering flexibility in organizing fields based on screen size.


Input Groups:

Allows combining text fields with add-ons (like icons or text) using the input-group class, helpful for creating fields with units or labels.


Form Validation:

Validation states (using classes like is-valid and is-invalid) display immediate feedback for valid or invalid inputs, often with color-coded highlights and helper messages.


Floating Labels:

The form-floating class provides floating labels that move above the input field when it is focused, giving a modern and clean look.


Custom Checkboxes and Radio Buttons:

Bootstrap offers customizable, accessible checkboxes and radio buttons with the form-check class.


Control Sizing:

Easily adjust input field sizes using classes like form-control-lg (large) and form-control-sm (small) to fit the design requirements.


Easy Customization:

All components are styled to work out of the box, but you can also add custom CSS to extend or modify their appearance as needed.