>
HTML5 Form Attributes
Welcome, Guest

by Rishi on Monday, 20 June 2011
HTML5 Form Attributes


New form attributes:

  • autocomplete
  • novalidate

New input attributes:

  • autocomplete
  • autofocus
  • form
  • form overrides (formaction, formenctype, formmethod, formnovalidate, formtarget)
  • height and width
  • list
  • min, max and step
  • multiple
  • pattern (regexp)
  • placeholder
  • required

Browser Support

AttributeIEFirefoxOperaChromeSafari
autocomplete8.03.59.53.04.0
autofocusNo4.010.03.04.0
formNo4.09.510.0No
form overridesNo4.010.510.0No
height and width8.03.5�9.53.04.0
listNo4.09.5NoNo
min, max and stepNoNo9.53.0No
multipleNo3.511.03.04.0
novalidateNo4.011.010.0No
patternNo4.09.53.0No
placeholderNo4.011.03.03.0
requiredNo4.09.53.0No

autocomplete Attribute

The autocomplete attribute specifies that the form or input field should have an autocomplete function.

Note:�The autocomplete attribute works with <form>, and the following <input> types: text, search, url, telephone, email, password, datepickers, range, and color.

When the user starts to type in an autocomplete field, the browser should display options to fill in the field:

Example

<form action="demo_form.asp" method="get" 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>

Note:�In some browsers you may need to activate the autocomplete function for this to work.


autofocus Attribute

The autofocus attribute specifies that a field should automatically get focus when a page is loaded.

Note:�The autofocus attribute works with all <input> types.

Example

User name: <input type="text" name="user_name"� autofocus="autofocus" />

form Attribute

The form attribute specifies one or more forms the input field belongs to.

Note:�The form attribute works with all <input> types.

The form attribute must refer to the id of the form it belongs to:

Example

<form action="demo_form.asp" method="get" id="user_form">
First name:<input type="text" name="fname" />
<input type="submit" />
</form>
Last name: <input type="text" name="lname" form="user_form" />

Note:�To refer to more than one form, use a space-separated list.���


Form Override Attributes

The form override attributes allow you to override some of the attributes set for the form element.

The form override attributes are:

  • formaction - Overrides the form action attribute
  • formenctype - Overrides the form enctype attribute
  • formmethod - Overrides the form method attribute
  • formnovalidate - Overrides the form novalidate attribute
  • formtarget - Overrides the form target attribute

Note:�The form override attributes works with the following <input> types: submit and image.

Example

<form action="demo_form.asp" method="get" id="user_form">
E-mail: <input type="email" name="userid" /><br />
<input type="submit" value="Submit" />
<br />
<input type="submit" formaction="demo_admin.asp" value="Submit as admin" />
<br />
<input type="submit" formnovalidate="true"
value="Submit without validation" />
<br />
</form>

Note: These attributes are helpful for creating different submit buttons.


height and width Attributes

The height and width attributes specifies the height and width of the image used for the input type image.

Note:�The height and width attributes only works with <input> type: image.

Example

<input type="image" src="/img_submit.gif" width="24" height="24" />



list Attribute

The list attribute specifies a datalist for an input field. A datalist is a list of options for an input field.

Note:�The list attribute works with the following <input> types: text, search, url, telephone, email, date pickers, number, range, and color.

Example

Webpage: <input type="url" list="url_list" name="link" />
<datalist id="url_list">
<option label="W3Schools" value="http://www.w3schools.com" />
<option label="Google" value="http://www.google.com" />
<option label="Microsoft" value="http://www.microsoft.com" />
</datalist>



min, max and step Attributes

The min, max and step attributes are used to specify restrictions for input types containing numbers or dates.

The max attribute specifies the maximum value allowed for the input field.

The min attribute specifies the minimum value allowed for the input field.

The step attribute specifies the legal number intervals for the input field (if step="3", legal numbers could be -3,0,3,6, etc).

Note:�The min, max, and step attributes works with the following <input> types: date pickers, number, and range.

The example below shows a numeric field that accepts values between 0 and 10, with a step of 3 (legal numbers are 0, 3, 6 and 9):

Example

Points: <input type="number" name="points" min="0" max="10" step="3" />


multiple Attribute

The multiple attribute specifies that multiple values can be selected for an input field.

Note:�The multiple attribute works with the following <input> types: email, and file.

Example

Select images: <input type="file" name="img" multiple="multiple" />



novalidate Attribute

The novalidate attribute specifies that the form or input field should not be validated when submitted.

If this attribute is present the form will not validate form input.

Note: The novalidate attribute works with: <form> and the following <input> types: text, search, url, telephone, email, password, date pickers, range, and color.

Example

<form action="demo_form.asp" novalidate="novalidate">
E-mail: <input type="email" name="user_email" />
<input type="submit" />
</form>



pattern Attribute

The pattern attribute specifies a pattern used to validate an input field.

Note:�The pattern attribute works with the following <input> types: text, search, url, telephone, email, and password

The example below shows a text field that can only contain three letters (no numbers or special characters):

Example

Country code: <input type="text" name="country_code"
pattern="[A-z]{3}" title="Three letter country code" />


placeholder Attribute

The placeholder attribute provides a hint that describes the expected value of an input field.

Note:�The placeholder attribute works with the following <input> types: text, search, url, telephone, email, and password

The hint is displayed in the input field when it is empty, and disappears when the field gets focus:

Example

<input type="search" name="user_search"� placeholder="Search W3Schools" />


required Attribute

The required attribute specifies that an input field must be filled out before submitting.

Note:�The required attribute works with the following <input> types: text, search, url, telephone, email, password, date pickers, number, checkbox, radio, and file.

Example

Name: <input type="text" name="usr_name" required="required" />



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering