Validation

Form validation ensures that the user enters the data that is required and in a correct format, by highlighting errors in their input. This is of equal importance for checkboxes, radio buttons and other form elements.

We included validation styles on form controls. To use, add .has-error to the parent element. Any .control-label, .form-control, and .help-block within that element will receive the validation styles.

Demo enabled on this page! The enhanced keyboard-focus behaviour is active on this page — the .keyboard-focus class is added to each .form-group while a control is keyboard-focused, and removed on blur, click or typing. Try pressing Tab to navigate through the form fields. Read more in the Forms accessibility guidelines.


Inputs, selects and textareas

Add .has-error to the parent .form-group. Inputs, selects, and textareas display errors inline below the field using .help-block with an alert icon.

Error text placed here
Error text placed here
0 /120
Error text placed here

Checkboxes and radio buttons

Add .has-error to the parent .form-group. Use the inline .help-block shown above for the error message — it applies to checkboxes and radio buttons exactly as it does to the other controls, and it is the pattern the consumer documentation recommends.

The example below shows the legacy tooltip variant, retained for backwards compatibility while input, select and textarea lose it in v3.0. It is mouse-only: the icon is a non-focusable <span> revealed on hover, so keyboard and screen-reader users cannot reach the message. Prefer the inline .help-block for new work.


Required fields

For a required field, use .required class on the .form-group div.

Form group heading 1
Form group heading 2
Form group heading 3
Form group heading 4