Create responsive layouts quickly with Bootstrap grid, utilities, components, and theming.
Lessons
Show valid and invalid states with feedback messages.
Form Validation is easiest to learn by reading the example, changing it, and observing the result.
<form class="needs-validation" novalidate>
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" required>
<div class="invalid-feedback">Please enter your name.</div>
<div class="valid-feedback">Looks good!</div>
</div>
<button class="btn btn-primary" type="submit">Submit</button>
</form>
<script>
document.querySelectorAll('.needs-validation').forEach(form => {
form.addEventListener('submit', e => {
if (!form.checkValidity()) { e.preventDefault(); e.stopPropagation(); }
form.classList.add('was-validated');
});
});
</script>Practice the Form Validation example in a small scratch file, then explain what changed and why.