Course Content
Bootstrap 5 Alerts
0/1
Progress Bars
0/1
Spinners
0/1
Pagination
0/1
List Groups
0/1
Bootstrap 5 Scrollspy
0/1
Bootstrap
About Lesson

BS5 Form Validation

Bootstrap 5 provides built-in validation styles to indicate valid and invalid inputs.

  • .is-invalid → Adds red styling for invalid input.
  • .is-valid → Adds green styling for valid input.
  • .invalid-feedback → Displays an error message.

Example:

HTML
<form class="needs-validation" novalidate>
  <div class="mb-3">
    <label for="validationInput" class="form-label">Enter your email</label>
    <input type="email" class="form-control is-invalid" id="validationInput" required>
    <div class="invalid-feedback">Please enter a valid email.</div>
  </div>
  
  <button type="submit" class="btn btn-primary">Submit</button>
</form>

Output: