Quackit Logo

FREE Hosting!

With every domain name you register with ZappyHost, you get FREE hosting.

$1.99 Domain Names

With every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99.

HTML 5 <input> Tag

Print Version

The HTML <input> tag is used within a form to declare an input element - a control that allows the user to input data.

Example

Modify the code below, then click "Update". See below for attributes.

Source CodeResult

Attributes

HTML tags can contain one or more attributes. Attributes are added to a tag to provide the browser with more information about how the tag should appear or behave. Attributes consist of a name and a value separated by an equals (=) sign, with the value surrounded by double quotes. Here's an example, style="color:black;".

There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes.

The attributes that you can add to this tag are listed below.

Element-Specific Attributes

The following table shows the attributes that are specific to this tag/element.

AttributeDescription
acceptSpecifies a comma-separated list of content types that the server accepts.

Possible values:

  • audio/*
  • video/*
  • image/*
  • [A valid MIME type, with no parameters]
actionSpecifies the URL of the file that will process the control when submitted.
altAlternate text. This specifies text to be used in case the browser/user agent can't render the input control.
autocompletePrevents the browser from using "autocomplete" with this control. Can be useful for sensitive data, such as banking details etc.

Possible values:

  • on (default value)
  • off
autofocusAutomatically gives focus to this control when the page loads. This allows the user to start using the control without having to select it first. There must not be more than one element in the document with the autofocus attribute specified.

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either autofocus or autofocus="autofocus").

Possible values:

  • [Empty string]
  • autofocus
checkedThe input control will already be selected when the page loads. Used with type="radio" or type="checkbox".
disabledDisables the input control. The control won't accept changes from the user. It also cannot receive focus and will be skipped when tabbing.

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either disabled or disabled="disabled").

Possible values:

  • [Empty string]
  • disabled
enctypeSpecifies the content type used to encode the form data set when it's submitted to the server.

Possible values:

  • application/x-www-form-urlencoded (default)
  • multipart/form-data (use this when uploading files)
  • text/plain (use this when uploading files)
formSpecifies the ID of a form to which this control belongs.

Possible values:

[The ID of a form element in the element's owner Document]

heightSpecifies the height of the control.
listSpecifies a datalist element to use for a list of predefined options for the user. The value must be the ID of a datalist element in the same document.
maxSpecifies the maximum value for the control.
maxlengthSpecifies the maximum number of characters that the user is allowed to enter into the text field.
methodSpecifies the HTTP method to use when the control is submitted.

Possible values:

  • get (the form data is appended to the URL when submitted)
  • post (the form data is not appended to the URL)
  • put
  • delete
minSpecifies the minimum value for the control.
multipleSpecifies whether the user is allowed to enter more than one value.

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either multiple or multiple="multiple").

Possible values:

  • [Empty string]
  • multiple
nameAssigns a name to the input control.
novalidateSpecifies that the form is not to be validated during submission.

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either novalidate or novalidate="novalidate").

Possible values:

  • [Empty string]
  • novalidate
patternSpecifies a regular expression against which the control's value is to be checked. Value must match the Pattern production of ECMA 262's grammar.
placeholderSpecifies a short hint (a word or short phrase) intended to aid the user with data entry. A hint could be a sample value or a brief description of the expected format.

Note: For a longer hint or other advisory text, the title attribute is more appropriate.

readonlySets the input control to read-only - it won't allow the user to change the value. The control however, can receive focus and are included when tabbing through the form controls.

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either readonly or readonly="readonly").

Possible values:

  • [Empty string]
  • readonly
requiredSpecifies that the input field is a required field (the user must complete this field).

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either required or required="required").

Possible values:

  • [Empty string]
  • required
sizeSpecifies the width of the control, in characters. Value that is a valid non-negative integer greater than zero.
srcIf type="image", this attribute specifies the location of the image.
stepSpecifies the granularity that is expected (and required) of the value, by limiting the allowed values.
targetSpecifies the browsing context to load the destination indicated in the action attribute.

Possible values:

  • _blank
  • _self
  • _top
  • _parent
typeSpecifies the type of control.

Possible values:

  • hidden
  • text
  • search
  • url
  • email
  • password
  • datetime
  • date
  • month
  • week
  • time
  • datetime-local
  • number
  • range
  • color
  • checkbox
  • radio
  • file
  • submit
  • image
  • reset
  • button
valueSpecifies the intial value for the control. Note: If type="checkbox" or type="radio" this attribute is required.
widthSpecifies the width of the control.

Global Attributes

The following attributes are standard across all HTML 5 tags.

class id style
contenteditable irrelevant tabindex
contextmenu lang template
dir ref title
draggable registrationmark  

For a full explanation of these attributes, see HTML 5 global attributes.

Event Handler Content Attributes

Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.

Here are the standard HTML 5 event handler content attributes.

onabort ondragover onmousemove
onbeforeunload ondragstart onmouseout
onblur ondrop onmouseover
onchange onerror onmouseup
onclick onfocus onmousewheel
oncontextmenu onkeydown onresize
ondblclick onkeypress onscroll
ondrag onkeyup onselect
ondragend onload onstorage
ondragenter onmessage onsubmit
ondragleave onmousedown onunload

For a full explanation of these attributes, see HTML 5 event handler content attributes.

Also see the HTML 4.01 tags


Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
               
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!