Examples and usage guidelines for form control styles, layout options, and custom components for creating a wide variety of forms.
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.
Sizing
Set heights using classes like .form-control-lg and .form-control-sm.
Disabled
Add the disabled boolean attribute on an input to prevent user interactions and make it appear lighter.
Help text
Block-level help text in forms can be created using .form-text (previously known as .help-block in v3). Inline help text can be flexibly implemented using any inline HTML element and utility classes like .text-muted.
Help text below inputs can be styled with .form-text. This class includes display: block and adds some top margin for easy spacing from the inputs above.
Your password must be 8-20 characters long, contain letters and numbers, and must not contain spaces, special characters, or emoji.
Checkboxes and Radios
Each checkbox and radio is wrapped in a <div> with a sibling <span> to create our custom control and a <label> for the accompanying text. Structurally, this is the same approach as our default .form-check.
We use the sibling selector (~) for all our <input> states—like :checked—to properly style our custom form indicator. When combined with the .custom-control-label class, we can also style the text for each item based on the <input>’s state.
We hide the default <input> with opacity and use the .custom-control-label to build a new custom form indicator in its place with ::before and ::after. Unfortunately we can’t build a custom one from just the <input> because CSS’s content doesn’t work on that element.
Checkboxes
If you’re using jQuery, something like this should suffice:
Radio
Valiation
Here’s how form validation works with Bootstrap:
HTML form validation is applied via CSS’s two pseudo-classes, :invalid and :valid. It applies to <input>, <select>, and <textarea> elements.
Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form>. Otherwise, any required field without a value shows up as invalid on page load. This way, you may choose when to activate them (typically after form submission is attempted).
Due to constraints in how CSS works, we cannot (at present) apply styles to a <label> that comes before a form control in the DOM without the help of custom JavaScript.
You may provide custom validity messages with setCustomValidity in JavaScript.
Search
Here’s style of the Search field
Select 2
Select2 v4 theme for Bootstrap4 (Compatible to boostrap 4.0.0+) It's requried Bootstrap Theme CSS select2-bootstrap4.min.css and select2.min.css both are required.
Select2 Library is hosted on the jsDelivr and cdnjs CDNs.
Date Picker
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.