+++ title = "General Forms" author = "Studio KonKon" description = "Styles, layout options and general components for creating a wide variety of forms." body_class = "bg-body-secondary" [[extra_js]] src = "forms.js" [[extra_css]] src = "dev-sk-ui" type = "scss" +++ {{< add-style >}} .fcs-example > .form-control + .form-control { margin-top: .5rem; } {{< /add-style >}}
Here's a quick example to demonstrate Bootstrap's form styles. Keep reading for documentation on required classes, form layout and more.
Form text below inputs can be styled with .form-text. If a block-level element will be used, a top margin is added for easy spacing from the inputs above.
Inline text can use any typical inline HTML element (be it a <span>, <small>, or something else) with nothing more than the .form-text class.
Add the disabled boolean attribute on an input to prevent user interactions and make it appear lighter.
Give textual form controls like <input>s and <textarea>s an upgrade with custom styles, sizing, focus states and more.
Set heights using classes like .form-control-lg and .form-control-sm.
Add the Disabled boolean attribute on an input to give it a grayed out appearance and remove pointer events.
Add the readonly boolean attribute on an input to prevent modification of the input’s value.
Use the .form-control-plaintext class to remove the default form field styling and preserve the correct margin and padding.
<select> menus need only a custom class, .form-select to trigger the custom styles.
multiple attribute is also supported:
disabled boolean attribute on a select to give it a grayed out appearance and remove pointer events.
:indeterminate pseudo class when manually set via JavaScript (there is no available HTML attribute for specifying it).
disabled attribute and the associated <label>s are automatically styled to match with a lighter color to help indicate the input’s state.
.form-switch class to render a toggle switch. Switches also support the disabled attribute.
.form-check-inline to any .form-check.
.btn styles rather than .form-check-label on the <label> elements. These toggle buttons can further be grouped in a button group if needed.
<input type="range"> controls with .form-range.
disabled boolean attribute on an input to give it a grayed out appearance and remove pointer events.
min and max—0 and 100, respectively.
step value.
.flex-nowrap.
.input-group-sm or .input-group-lg and contents within will automatically resize. Sizing on the individual input group elements isn’t supported.
<input>s are supported visually, validation styles are only available for input groups with a single <input>.
<input class="form-control"> and <label> elements in .form-floating to enable floating labels with Bootstrap’s textual form fields.
.form-control, floating labels are only available on .form-selects. They work in the same way but unlike <input>s, they’ll always show the <label> in its floated state. Selects with size and multiple are not supported.
By default, <textarea>s with .form-control will be the same height as <input>s.
To set a custom height on your <textarea>, do not use the rows attribute. Instead, set an explicit height (either inline or via custom CSS).
.row class to form groups and using the .col-*-* classes to specify the width of your labels and controls. Be sure to add .col-form-label to your <label>s as well so they’re vertically centered with their associated form controls.
.col-form-label-sm or .col-form-label-lg to your <label>s or <legend>s to correctly follow the size of .form-control-lg and .form-control-sm.
.cols within a .row. They’ll split the available width equally between them. You may also pick a subset of your columns to take up more or less space, while the remaining .cols equally split the rest, with specific column classes like .col-sm-7.
.col-auto class to create horizontal layouts. The .align-items-center aligns the form elements to the middle, making the .form-checkbox align properly.
.col to .col-auto so that your columns only take up as much space as needed. Put another way, the column sizes itself based on the contents.
Remixed with size-specific column classes
Custom feedback styles apply custom colors, borders, focus styles and background icons to better communicate feedback. Background icons for <select>s are only available with .form-select and not .form-control.
For custom Bootstrap form validation messages, you’ll need to add the novalidate boolean attribute to your <form>. This disables the browser default feedback tooltips but still provides access to the form validation APIs in JavaScript.
If using client-side validation but require server-side validation, you can indicate invalid and valid form fields with .is-invalid and .is-valid. Note that .invalid-feedback is also supported with these classes.
If your form layout allows it, you can swap the .{valid|invalid}-feedback classes for .{valid|invalid}-tooltip classes to display validation feedback in a styled tooltip. Be sure to have a parent with position: relative on it for tooltip positioning. In the example below, our column classes have this already, but your project may require an alternative setup.