Validation Attributes

In this lesson, we will cover some very useful HTML attributes that will help us perform automatic validation. Let's begin!

HTML5 extended the <input> tag with new attributes that specify different kinds of automatic validation. With the required attribute you can specify that an input field must be filled out before submitting the form. When you work with text input, use maxlength to define the maximum number of characters allowed in the field.

In the case of numeric values (number, range, and date related input fields) you can specify an acceptable range with the min and max attributes, and optionally define the legal number intervals with the step attribute. For example, the following markup defines a numeric field that can have only the -3, 1, 5, and 9 values:

Get hands-on with 1200+ tech skills courses.