Components Lesson 8 of 12
Bootstrap Forms
Build good-looking forms with Bootstrap — form-control, form-label, form-select, checks and radios, floating labels, input groups, grid layouts and validation styles.
Forms are where users do things: register, log in, order. Bootstrap makes form controls consistent, touch-friendly and easy to lay out.
Basic form controls
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3" style="max-width: 480px">
<form>
<div class="mb-3">
<label for="name" class="form-label">Full name</label>
<input id="name" class="form-control" placeholder="Juan Dela Cruz">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input id="email" type="email" class="form-control">
<div class="form-text">We'll never share your email.</div>
</div>
<div class="mb-3">
<label for="strand" class="form-label">Strand</label>
<select id="strand" class="form-select">
<option>STEM</option><option>ABM</option><option>HUMSS</option><option>TVL-ICT</option>
</select>
</div>
<div class="mb-3">
<label for="why" class="form-label">Why do you want to join?</label>
<textarea id="why" class="form-control" rows="3"></textarea>
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" id="agree">
<label class="form-check-label" for="agree">I agree to the club rules</label>
</div>
<button class="btn btn-primary w-100">Register</button>
</form>
</div>
form-controlfor inputs and textareas,form-selectfor dropdowns.form-labelfor labels,form-textfor help text.form-check,form-check-inputandform-check-labelfor checkboxes and radios.mb-3on each group adds space between fields.
Radios and switches
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="p-3">
<p class="mb-1">Shift:</p>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="shift" id="am" checked>
<label class="form-check-label" for="am">Morning</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="shift" id="pm">
<label class="form-check-label" for="pm">Afternoon</label>
</div>
<div class="form-check form-switch mt-3">
<input class="form-check-input" type="checkbox" role="switch" id="notif">
<label class="form-check-label" for="notif">Send me SMS reminders</label>
</div>
</div>
Form layout with the grid
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3">
<form class="row g-3">
<div class="col-md-6">
<label class="form-label" for="fn">First name</label>
<input class="form-control" id="fn">
</div>
<div class="col-md-6">
<label class="form-label" for="ln">Last name</label>
<input class="form-control" id="ln">
</div>
<div class="col-md-8">
<label class="form-label" for="brgy">Barangay</label>
<input class="form-control" id="brgy">
</div>
<div class="col-md-4">
<label class="form-label" for="zip">ZIP</label>
<input class="form-control" id="zip">
</div>
</form>
</div>
Input groups and floating labels
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3" style="max-width: 420px">
<div class="input-group mb-3">
<span class="input-group-text">₱</span>
<input type="number" class="form-control" placeholder="Amount">
<span class="input-group-text">.00</span>
</div>
<div class="form-floating">
<input type="email" class="form-control" id="fl" placeholder="name@example.com">
<label for="fl">Email address</label>
</div>
</div>
Validation styles
<link rel="stylesheet" href="/vendor/bootstrap.min.css">
<div class="container py-3" style="max-width: 420px">
<form id="f" class="needs-validation" novalidate>
<label class="form-label" for="cp">Mobile number</label>
<input class="form-control" id="cp" pattern="09[0-9]{9}" required placeholder="09XXXXXXXXX">
<div class="invalid-feedback">Enter 11 digits starting with 09.</div>
<div class="valid-feedback">Looks good!</div>
<button class="btn btn-primary mt-3">Submit</button>
</form>
</div>
<script>
document.getElementById("f").addEventListener("submit", (e) => {
const form = e.target;
if (!form.checkValidity()) e.preventDefault();
form.classList.add("was-validated");
});
</script>
When the form gets the class was-validated, Bootstrap colors each field green or red based on the HTML rules (required, pattern), and shows the matching valid-feedback or invalid-feedback message.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04