Bootstrap 5 Form

Forms in Bootstrap 5 provide a wide range of features for creating accessible, responsive, and aesthetically pleasing forms. Built-in classes make it easy to style form controls and validate user input.

Bootstrap 5 Form with Validation

Looks good!
Please provide a valid email.
Looks good!
Please provide a password.
You must agree before submitting.
Example
<div class="container mt-5">
<h2>Bootstrap 5 Form with Validation</h2>
<form class="needs-validation" novalidate>
<!-- Email -->
<div class="mb-3">
<label for="validationEmail" class="form-label">Email address</label>
<input type="email" class="form-control" id="validationEmail" required>
<div class="valid-feedback">Looks good!</div>
<div class="invalid-feedback">Please provide a valid email.</div>
</div>
<!-- Password -->
<div class="mb-3">
<label for="validationPassword" class="form-label">Password</label>
<input type="password" class="form-control" id="validationPassword" required>
<div class="valid-feedback">Looks good!</div>
<div class="invalid-feedback">Please provide a password.</div>
</div>
<!-- Checkbox -->
<div class="form-check mb-3">
<input type="checkbox" class="form-check-input" id="validationCheck" required>
<label class="form-check-label" for="validationCheck">Agree to terms and conditions</label>
<div class="invalid-feedback">You must agree before submitting.</div>
</div>
<!-- Submit -->
<button class="btn btn-primary" type="submit">Submit</button>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
(() => {
'use strict';
const forms = document.querySelectorAll('.needs-validation');
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
})();
</script>

Try it yourself


Whereisstuff is simple learing platform for beginer to advance level to improve there skills in technologies.we will provide all material free of cost.you can write a code in runkit workspace and we provide some extrac features also, you agree to have read and accepted our terms of use, cookie and privacy policy.
© Copyright 2024 www.whereisstuff.com. All rights reserved. Developed by whereisstuff Tech.