--- 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 currently recommend using custom validation styles, as native browser default validation messages are not consistently exposed to assistive technologies in all browsers (most notably, Chrome on desktop and mobile). {{< /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 ``, `
@
{{< /example >}} ## Feedback messages You can insert custom feedback messages with the `.valid-feedback` or `.invalid-feedback` that replaces the browser’s default feedback messages. {{< example >}}
Example valid feedback text
Example valid feedback text
@
Example invalid feedback text
Example invalid feedback text
Example invalid feedback text
Example invalid feedback text
Example invalid feedback text
{{< /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 >}}
Example valid feedback text
Example valid feedback text
@
Example invalid feedback text
Example invalid feedback text
Example invalid feedback text
Example invalid feedback text
Example invalid feedback text
{{< /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.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" >}}