HTML5 Form Attributes HTML5 New Form Attributes The HTML5 and tag has several new attributes. New attributes: autocomplete novalidate New attributes: autocomplete autofocus form formaction formenctype formmethod formnovalidate formtarget height and width list min and max multiple pattern (regexp) placeholder required step / autocomplete property The autocomplete attribute specifies that a form or input field should have autocomplete functionality. When a user starts typing in an autocomplete field, the browser should display the options for filling in that field. Tip: The autocomplete attribute may be enabled in the form element but disabled in the input element. Note: autocomplete applies to the tag, and to the following types of tags: text, search, url, telephone, email, password, datepickers, range, and color. Example Enable autocomplete in an HTML form (with one input field having autocomplete turned off): <form action="demo-form.php" autocomplete="on">First name: <input type="text" name="fname"> <br>Last name: <input type="text" name="lname"> <br>E-mail: <input type="email" name="email" autocomplete="off"> <br> <input type="submit" form>Try it » **Tip:** In some browsers, you may need to enable the autocomplete feature for this attribute to take effect. The novalidate attribute novalidate is a boolean (true or false) attribute. The novalidate attribute is a boolean attribute of HTML form elements, used to set the browser to not validate the form. When this attribute is added to an element, the browser will not perform default form validation and will not check whether input fields meet the specified validation rules. Using the novalidate attribute allows developers to fully control the form validation logic, and to customize the behavior of form validation through JavaScript or other means. Example Submit form data without validation <form action="demo-form.php" novalidate>E-mail: <input type="email" name="user_email"> <input type="submit" form>Try it » autofocus attribute The autofocus attribute is a boolean attribute. The autofocus attribute specifies that a field automatically gains focus when the page loads. Example Make the "First name" input field automatically focused when the page loads: First name: <input type="text" name="fname" autofocus>Try it » form attribute The form attribute specifies one or more forms to which an input field belongs. **Tip:** To reference more than one form, use a space-separated list. Example An input field located outside a form references an HTML form (the input still belongs to part of the form): <form action="demo-form.php" id="form1">First name: <input type="text" name="fname"> <br> <input type="submit" value="Submit" form>Last name: <input type="text" name="lname" form="form1">Try it » formaction attribute The formaction attribute is used to describe the URL address for form submission. The formaction attribute overrides the action attribute in the element. **Note: **The formaction attribute is used with type="submit" and type="image". Example The following HTML form contains two submit buttons with different addresses: <form action="demo-form.php">First name: <input type="text" name="fname"> <br>Last name: <input type="text" name="lname"> <br> <input type="submit" value="Submit"> <br> <input type="submit" formaction="demo-admin.php" value="Submit" form>Try it » formenctype attribute The formenctype attribute describes the data encoding for form submission to the server (only for forms with method="post") The formenctype attribute overrides the enctype attribute of the form element. **Important: **This attribute is used together with type="submit" and type="image". Example The first submit button sends form data with the default encoding, and the second submit button sends form data in "multipart/form-data" encoding format: <form action="demo-post_enctype.php" method="post">First name: <input type="text" name="fname"> <br> <input type="submit" value="Submit"> <input type="submit" formenctype="multipart/form-data" value=">Submit with Multipart/form-data " form Try it » formmethod attribute The formmethod attribute defines the method of form submission. The formmethod attribute overrides the method attribute of the element. Note: This attribute can be used together with type="submit" and type="image". Example Example of redefining the form submission method: <form action="demo-form.php" method="get">First name: <input type="text" name="fname"> <br>Last name: <input type="text" name="lname"> <br> <input type="submit" value="Submit"> <input type="submit" formmethod="post" formaction="demo-post.php" value=">Submit using POST " form Try it » formnovalidate attribute The novalidate attribute is a boolean attribute. The novalidate attribute describes that the element does not need to be validated when the form is submitted. The formnovalidate attribute overrides the novalidate attribute of the element. Note: The formnovalidate attribute is used together with type="submit" Example A form with two submit buttons (with and without validation): <form action="demo-form.php">E-mail: <input type="email" name="userid"> <br> <input type="submit" value="Submit"> <br> <input type="submit" formnovalidate value=">Submit without validation " form Try it » formtarget attribute The formtarget attribute specifies a name or a keyword to indicate where to display the response received after form submission. The formtarget attribute overrides the target attribute of the element. Note: The formtarget attribute is used with type="submit" and type="image" . Example a form with two submit buttons, displayed in different windows: <form action="demo-form.php">First name: <input type="text" name="fname"> <br>Last name: <input type="text" name="lname"> <br> <input type="submit" value=">Normal submission " <input type="submit" formtarget="_blank" value=">Submit to a new page " form Try it » The height and width Attributes The height and width attributes specify the image height and width for the image-type tag. Note: The height and width attributes only apply to the image-type tag. **Tip:** Images usually have both height and width attributes specified. If an image has height and width set, the space required by the image is reserved when the page is loaded. Without these attributes, the browser does not know the size of the image and cannot reserve appropriate space. The image causes the page layout to change during loading (even after the image has loaded). Example Define an image submit button using the height and width attributes: Try it » The list attribute The list attribute specifies a datalist for an input field. A datalist is a list of options for an input field. Example in predefined in values: Try it » The min and max Attributes The min, max, and step attributes are used to specify constraints for input types that contain numbers or dates. Note: The min, max, and step attributes apply to the following types of tags: date pickers, number, and range. Example Setting the minimum and maximum values of an element: Enter a date before 1980-01-01: Enter a date after 2000-01-01: Quantity (between 1 and 5): Try it » multiple property The multiple attribute is a boolean attribute. The multiple attribute specifies that multiple values can be selected in the element. Note: The multiple attribute applies to the following types of tags: email and file: Example Upload multiple files: Select images: Try it » pattern property The pattern attribute describes a regular expression used to validate The value of the element. **Note:** The pattern attribute applies to the following types of tags: text, search, url, tel, email, and password. Tip: is used as a global title attribute to describe the pattern. Tip: You can find it in our JavaScript Tutorialwhere you can learn about regular expressions. Example The following example shows a text field that can only contain three letters (no numbers or special characters): Country code: Try it » placeholder property The placeholder attribute provides a hint describing the expected value of an input field. A short hint is displayed in the input field before the user enters a value. Note: The placeholder attribute applies to the following types of tags: text, search, url, telephone, email, and password. Example Input field hint text: Try it » required attribute The required attribute is a boolean attribute. The required attribute specifies that an input field must be filled in before submission (it cannot be empty). **Note:** The required attribute applies to the following types of tags: text, search, url, telephone, email, password, date pickers, number, checkbox, radio, and file. Example Input fields that cannot be empty: Username: Try it » The step attribute The step attribute specifies the legal number intervals for an input field. If step="3", the legal numbers are -3, 0, 3, 6, etc. Tip: The step attribute can be used together with the max and min attributes to create a range of values. Note: The step attribute is used with the following type values: number, range, date, datetime, datetime-local, month, time, and week. Example Specify an input step of 3: Try it » HTML5 tag tag Description Define a form Define an input field