--- layout: docs title: Validation description: Provide valuable, actionable feedback to your users with HTML5 form validation, via browser default behaviors or custom styles and JavaScript. group: forms toc: true extra_js: - src: "/docs/5.0/assets/js/validate-forms.js" async: true --- {{< callout warning >}} We are aware that currently the client-side custom validation styles and tooltips are not accessible, since they are not exposed to assistive technologies. While we work on a solution, we'd recommend either using the server-side option or the default browser validation method. {{< /callout >}} ## How it works 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 ``, `
Please enter a message in the textarea.
Example invalid feedback text
More example invalid feedback text
Example invalid select feedback
Example invalid form file feedback
{{< /example >}} ## Tooltips 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. {{< example >}}
Looks good!
Looks good!
@
Please choose a unique and valid username.
Please provide a valid city.
Please select a valid state.
Please provide a valid zip.
{{< /example >}} ## Customizing Validation states can be customized via Sass with the `$form-validation-states` map. Located in our `_variables.scss` file, this Sass map is looped over to generate the default `valid`/`invalid` validation states. Included is a nested map for customizing each state's color and icon. While no other states are supported by browsers, those using custom styles can easily add more complex form feedback. Please note that we do not recommend customizing these values without also modifying the `form-validation-state` mixin. This is the Sass map from `_variables.scss`. Override this and recompile your Sass to generate different states: {{< scss-docs name="form-validation-states" file="scss/_variables.scss" >}} This is the loop from `forms/_validation.scss`. Any modifications to the above Sass map will be reflected in your compiled CSS via this loop: {{< scss-docs name="form-validation-states-loop" file="scss/forms/_validation.scss" >}}