HTML Tutorial
HTML - Introduction HTML - Basic HTML - Structure HTML - Element HTML - Attributes HTML - Headings HTML - Paragraphs HTML - Styles HTML - Formatting HTML - Phrase Tags HTML - Quotations HTML - Comments HTML - Colors HTML - CSS HTML - Links HTML - Images HTML - Tables HTML - List HTML - Inline elements HTML - Block elements HTML - Classes HTML - Id HTML - Javascript HTML - File Path HTML - Iframe HTML - Responsive HTML - Computer Code HTML - Head tag HTML - Events HTML - Url Encoding HTML - Entities HTML - Validation
HTML Forms
HTML - Forms HTML - Form Elements HTML - Input types HTML - Input Attributes
HTML5
HTML5 - Introduction HTML5 - New Elements HTML5 - Semantics HTML5 - Style Guide
HTML Media
HTML - Video HTML - Audio HTML - Embed Multimedia
HTML Graphics
HTML - Canvas HTML - SVG
HTML APIs
HTML - Geolocation HTML - Drag & drop HTML - Web Storage HTML - Web Workers
HTML References
HTML - Tag Reference HTML - Tag by Category HTML - Attributes HTML - Global Attributes HTML - Events HTML - Language Codes HTML - Country Codes HTML - URL Encoding HTTP Methods HTTP Status Codes <input> types

HTML Input Attributes

The value Attribute

The value attribute specifies the initial value for an input field.

Run code

The disabled Attribute

The disabled is a boolean attribute indicates that the user cannot interact with the element.

A disabled input field is un-clickable and also, a disabled control's value isn't submitted with the form.

Run code

The checked Attribute

The checked is a boolean attribute specifies that an input element should be pre-selected (checked) when the page loads.

The checked attribute can be used with <input type="checkbox"> and <input type="radio">.

Run code

The readonly Attribute

The readonly is a boolean attribute specifies that the user cannot modify the value of the input element.

Run code

The maxlength Attribute

The maxlength attribute specifies the maximum number of characters that the user can enter.

This attribute applies only when the type attribute is set to text, search, tel, url, email, or password, otherwise it is ignored.

Run code

The minlength Attribute

The minlength attribute specifies the minimum number of characters required that the user should enter.

This attribute applies only when the type attribute is set to text, search, tel, url, email, or password, otherwise it is ignored.

Run code

The size Attribute

The size attribute specifies the visible width for the input element.

This attribute applies only when the type attribute is set to text, search, tel, url, email, or password, otherwise it is ignored.

Run code

New HTML5 Input Attributes

HTML5 has introduced many form input attributes:

  • autocomplete
  • autofocus
  • form
  • formaction
  • formenctype
  • formmethod
  • formnovalidate
  • formtarget
  • list
  • max
  • min
  • multiple
  • pattern
  • placeholder
  • required
  • step

The autocomplete Attribute

The autocomplete attribute specifies whether the value of the input element can be automatically completed by the browser.

By default, browsers remember information that the user submits through input fields on websites.

This enables the browser to offer autocomplete. To disable autocompletion use autocomplete="off".

You can either do this for an entire form, or for specific input elements in a form.

For specific input elements:
Run code
For an entire form:
Run code

The autofocus Attribute

The autofocus is a boolean attribute specifies that a form element should have input focus when the page loads.

Run code

Only one form element in a document can have the autofocus attribute.


The placeholder Attribute

The placeholder attribute lets you specify a text that appears within the control element's content area itself when empty.

Run code

See how to apply CSS on placeholder attribute.


The required Attribute

The required is a boolean attribute specifies that the user must fill in a value before submitting the form to the server.

Run code

The min and max Attributes

The min and max attributes specify the minimum and maximum values for an input element.

The min and max attributes works with the following input types: number, range, date, datetime, datetime-local, month, time and week.

Run code

The step Attribute

The step attribute works with the min and max attributes to limit the increments at which a numeric or date-time value can be set.

Run code

The form Attribute

The form attribute specifies an input field located outside the HTML form, but still a part of the form.

The value of this attribute must be an id of a form element in the same document.

Run code

The formaction Attribute

The formaction attribute specifies the URL of a file that processes the information submitted by the input element.

This attribute overrides the action attribute.

The following example specifies a form with 2 submit input buttons. The first submit button submits the form data to "form-action.php", and the second submits to "form-action1.php":

Run code

The list Attribute

The list attribute identifies a list of pre-defined options to suggest to the user.

The value must be the id of a <datalist> element in the same document.

Run code

The multiple Attribute

The multiple attribute specifies that the user is allowed to enter more than one value in the input element.

This attribute works with <input type="email">, <input type="file"> and <select> element.

Run code

The Pattern Attribute

The pattern attribute defines a regular expression that the control's value is checked against.

Use the title attribute to describe the pattern to help the user.

The pattern attribute works with the following input types: text, date, search, url, tel, email, and password.

Run code

HTML Input Attributes

Here is the list of input attributes you can use in HTML form:

Attribute Description
autocomplete Indicates whether controls in this form can by default have their values automatically completed by the browser
autofocus The element should be automatically focused after the page loaded
checked Specifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio")
disabled Indicates whether the user can interact with the element
form Indicates the form that is the owner of the element
formaction Specifies where to send the form-data when a form is submitted (only for type="submit")
formenctype Specifies how the form data should be encoded when submitted (only for forms with method="post")
formmethod Defines the HTTP method for sending form-data to the action URL
formtarget Specifies a name or a keyword that indicates where to display the response that is received after submitting the form
list Identifies a list of pre-defined options to suggest to the user
max Indicates the maximum value allowed
min Indicates the minimum value allowed
maxlength Defines the maximum number of characters allowed in the element
minlength Defines the minimum number of characters allowed in the element
multiple Indicates whether multiple values can be entered in an input of the type email or file
name Specifies the name of the element. For example used by the server to identify the fields in form submits
pattern Defines a regular expression which the <input> element's value will be validated against
placeholder Provides a hint to the user of what can be entered in the field
readonly Specifies whether the element can be edited
required Indicates whether this element is required to fill out or not
selected Defines that an option should be pre-selected when the page loads
size Defines the width of the element (in pixels). If the element's type attribute is text or password then it's the number of characters
step Defines the legal number intervals for an input field
type Defines the type of element
value Defines a default value which will be displayed in the element on page load