Bs5 Forms in Bootstrap
Sure! Here’s a solid overview of Bootstrap 5 (BS5) Forms — flexible, responsive, and easy-to-style form components.
? BS5 Forms Overview
Bootstrap 5 provides a variety of classes and utilities to create stylish forms with minimal custom CSS. It supports:
Basic form controls (inputs, selects, textareas)
Inline forms
Horizontal forms
Floating labels
Validation states
Form layouts and sizing
? Basic Form Controls
<form> <div class="mb-3"> <label for="exampleInputEmail1" class="form-label">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" placeholder="name@example.com"> </div> <div class="mb-3"> <label for="examplePassword" class="form-label">Password</label> <input type="password" class="form-control" id="examplePassword" placeholder="Password"> </div> <div class="mb-3 form-check"> <input type="checkbox" class="form-check-input" id="exampleCheck"> <label class="form-check-label" for="exampleCheck">Check me out</label> </div> <button type="submit" class="btn btn-primary">Submit</button></form>? Inline Forms
Make forms inline for short forms or search bars:
<form class="row g-3 align-items-center"> <div class="col-auto"> <label for="inputName" class="col-form-label">Name</label> </div> <div class="col-auto"> <input type="text" id="inputName" class="form-control" placeholder="Jane Doe"> </div> <div class="col-auto"> <button type="submit" class="btn btn-primary">Submit</button> </div></form>? Horizontal Forms
Use Bootstrap grid to create horizontal form layouts:
<form> <div class="row mb-3"> <label for="inputEmail" class="col-sm-2 col-form-label">Email</label> <div class="col-sm-10"> <input type="email" class="form-control" id="inputEmail" placeholder="email@example.com"> </div> </div> <div class="row mb-3"> <label for="inputPassword" class="col-sm-2 col-form-label">Password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="inputPassword" placeholder="Password"> </div> </div> <button type="submit" class="btn btn-primary">Sign in</button></form>? Form Controls Variants
Sizing:
.form-control-lg,.form-control-smReadonly: add
readonlyattributeDisabled: add
disabledattribute or.disabledclassSelect: use
.form-selectTextarea: use
<textarea>with.form-control
? Floating Labels
Use .form-floating for floating label inputs (covered in detail earlier).
? Validation
Use .is-valid, .is-invalid, .valid-feedback, and .invalid-feedback for feedback styling (covered in form validation).
? Layout Utilities
You can use spacing (.mb-3, .mt-2) and grid (row, col-) utilities to customize layout.
If you want, I can give you code examples for any of these form types or advanced features like input groups, form checkboxes and radios, or custom file inputs!