New Input Tag Attributes in HTML 5
- The autocomplete attribute can be set to to off to require that your visitor enter the value that this field requires every time rather than their being able to tell their browser which value to use the first time they fill out the form and have the browser automatically fill out the field on subsequent visits. It should only be used where the field is expected to need a different value input into it on each visit and so should not be used when asking your visitor to supply information that will always be the same (except for password fields).
- The form attribute allows input fields to be placed outside of the form element to which they belong with this attribute containing the id of the form that this input belongs to. It would only need to be used if you have a situation where a particular form field needs to be located somewhere completely separate from the rest of the form. While I can't think of any instances where this would be needed there are obviously situations that others have come across where this is the case as otherwhise there would have been no reason for adding this attribute.
- A number of new attributes formaction, formenctype, formmethod, formnovalidate, and formtarget can be specified on a submit button or image in place of the equivalent attributes on the form tag itself. This would allow you to have multiple submit buttons that submit the same form data to different places in different ways depending on which of the submit buttons is used.
- The list attribute allows the id of a datalist to be specified so as to convert the input field into a combobox.
- The min and max attributes allow minimum and maximum values to be specified. Before the form is submitted the field will be validated to ensure that the value of the field is between these values.
- The multiple attribute indicates that the field is allowed to contain more than one value, each of which will be separately validated before the form is submitted.
- The pattern attribute allows a regular expression to be entered. The field will be validated to ensure that it matches this pattern before the form is submitted.
- The required attribute indicates that a field is required to have a value. Fields which are not required have an empty value as a possible valid input.
- The step attribute is used with some of the new input types to indicate how big a movement there should be if the current value is to be changed by a minimum amount.
Not all of these new attributes are available for every different type of input field and not all of them will necessarily be needed on those types where they are applicable. You will almost certainly find many occasions where these attributes would be useful though. It is just unfortunate that we have had to wait for HTML 5 for these attributes to be introduced.
This article written by Stephen Chapman, Felgall Pty Ltd.