Form Elements page header description goes here...
Form controls
Textual form controls—like <input>
s, <select>
s, and <textarea>
s—are styled with the .form-control class. Included are styles for general appearance, focus state, sizing, and more. Please read the official Bootstrap documentation for the full list of options.
<!-- text input -->
<div class="form-group mb-3">
<label class="form-label" for="exampleFormControlInput1">Email address</label>
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="[email protected]">
</div>
<!-- select -->
<select class="form-control">
...
</select>
<!-- multiple select -->
<select multiple class="form-control">
...
</select>
<!-- textarea -->
<textarea class="form-control" rows="3"></textarea>
<!-- file input -->
<input type="file" class="form-control" id="exampleFormControlFile1" />
Sizing
Set heights using classes like .form-control-lg
and .form-control-sm
.
<!-- input text -->
<input class="form-control form-control-lg" type="text" placeholder=".form-control-lg">
<input class="form-control" type="text" placeholder="Default input">
<input class="form-control form-control-sm" type="text" placeholder=".form-control-sm">
<!-- select -->
<select class="form-select form-select-lg">
<option>Large select</option>
</select>
<select class="form-select">
<option>Default select</option>
</select>
<select class="form-select form-select-sm">
<option>Small select</option>
</select>
Readonly
Add the readonly boolean attribute on an input to prevent modification of the input’s value. Read-only inputs appear lighter (just like disabled inputs), but retain the standard cursor.
<input class="form-control" type="text" placeholder="Readonly input here..." readonly />
Readonly plain text
If you want to have <input readonly>
elements in your form styled as plain text, use the .form-control-plaintext class to remove the default form field styling and preserve the correct margin and padding.
<div class="form-group row mb-3">
<label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" id="staticEmail" value="[email protected]">
</div>
</div>
Range inputs
Set horizontally scrollable range inputs using .form-range
.
<!-- default range -->
<input type="range" class="form-range" id="formControlRange" />
<!-- disabled range -->
<input type="range" class="form-range" id="disabledRange" disabled />
Checkboxes
Default checkboxes are improved upon with the help of .form-check
, a single class for both input types that improves the layout and behavior of their HTML elements.
<!-- checkbox -->
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1" disabled />
<label class="form-check-label" for="defaultCheck1">Default checkbox</label>
</div>
<!-- inline checkbox -->
<div class="form-check form-check-inline">
...
</div>
Radios
Default radios are improved upon with the help of .form-check
, a single class for both input types that improves the layout and behavior of their HTML elements. You can use Bootstrap custom radio for styled radio button.
<!-- radio -->
<div class="form-check">
<input class="form-check-input" type="radio" value="" id="defaultRadio1" disabled />
<label class="form-check-label" for="defaultRadio1">Default checkbox</label>
</div>
<!-- inline radio -->
<div class="form-check form-check-inline">
...
</div>
Switches
A switch has the markup of a custom checkbox but uses the .form-switch
class to render a toggle switch. Switches also support the disabled attribute.
<div class="form-check form-switch">
<input type="checkbox" class="form-check-input" id="customSwitch1">
<label class="form-check-label" for="customSwitch1">Toggle this switch element</label>
</div>
Select menu
Custom <select> menus need only a custom class, .form-select to trigger the custom styles. Custom styles are limited to the <select>’s initial appearance and cannot modify the <option>s due to browser limitations.
<!-- form select -->
<select class="form-select">
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<!-- form-select-lg -->
<select class="form-select form-select-lg">...</select>
<!-- form-select-sm -->
<select class="form-select form-select-sm">...</select>
File browser
The file input is the most gnarly of the bunch and requires additional JavaScript if you’d like to hook them up with functional Choose file… and selected file name text.
<div class="mb-3">
<label class="form-label" for="defaultFile">Choose file</label>
<input type="file" class="form-control" id="defaultFile" />
</div>
<!-- small input file -->
<input type="file" class="form-control form-control-sm" id="smFile" />
<!-- large input file -->
<input type="file" class="form-control form-control-lg" id="lgFile" />
Form grid
More complex forms can be built using bootstrap grid classes. Use these for form layouts that require multiple columns, varied widths, and additional alignment options.
<form>
<div class="mb-3 row">
<label for="inputEmail3" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3">
</div>
</div>
<div class="mb-3 row">
<div class="col-sm-10 offset-sm-2">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</form>
Help text
Block-level help text in forms can be created using .form-text
. Inline help text can be flexibly implemented using any inline HTML element and utility classes like .text-muted
.
<label for="inputPassword5">Password</label>
<input type="password" id="inputPassword5" class="form-control" aria-describedby="passwordHelpBlock">
<small id="passwordHelpBlock" class="form-text text-muted">
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
</small>
Input group
Place one add-on or button on either side of an input. You may also place one on both sides of an input. Remember to place <label>
outside the input group.
<div class="input-group flex-nowrap">
<span class="input-group-text" id="addon-wrapping">@</span>
<input type="text" class="form-control" placeholder="Username" />
<span class="input-group-text">.com</span>
</div>
Validation
Provide valuable, actionable feedback to your users with HTML5 form validation. Choose from the browser default validation feedback, or implement custom messages with our built-in classes and starter JavaScript.
<form class="was-validated">
<!-- valid input -->
<input type="text" class="form-control is-valid" value="" required />
<div class="valid-feedback">Looks good!</div>
<!-- invalid input -->
<input type="text" class="form-control is-invalid" value="" required />
<div class="invalid-feedback">Field is required</div>
<!-- valid tooltip -->
<div class="position-relative">
<div class="valid-tooltip">Looks good!</div>
</div>
<!-- invalid tooltip -->
<div class="position-relative">
<div class="invalid-tooltip">Field is required</div>
</div>
</form>