Breaking

Thursday, May 9, 2019

HTML input Tag

HTML <input> Tag


Example

An HTML form with three input fields; two text fields and one submit button:
<form action="/action_page.php">
  First name: <input type="text"name="fname"><br>
  Last name: <input type="text"name="lname"><br>
  <input type="submit"value="Submit">
</form>
Try it Yourself »

Definition and Usage

The <input> tag specifies an input field where the user can enter data.
<input> elements are used within a <form> element to declare input controls that allow users to input data.
An input field can vary in many ways, depending on the type attribute.

Browser Support

Element
<input>YesYesYesYesYes

Tips and Notes

Note: The <input> element is empty, it contains attributes only.
Tip: Use the <label> element to define labels for <input> elements.

Differences Between HTML 4.01 and HTML5

The "align" attribute is not supported in HTML5.
In HTML5, the <input> tag has several new attributes, and the type attribute has several new values.


Differences Between HTML and XHTML

In HTML, the <input> tag has no end tag.
In XHTML, the <input> tag must be properly closed, like this <input />.

Attributes

= New in HTML5.
AttributeValueDescription
acceptfile_extension
audio/*
video/*
image/*
media_type
Specifies a filter for what file types the user can pick from the file input dialog box (only for type="file")
alignleft
right
top
middle
bottom
Not supported in HTML5.
Specifies the alignment of an image input (only for type="image")
alttextSpecifies an alternate text for images (only for type="image")
autocompleteon
off
Specifies whether an <input> element should have autocomplete enabled
autofocusautofocusSpecifies that an <input> element should automatically get focus when the page loads
checkedcheckedSpecifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio")
dirnameinputname.dirSpecifies that the text direction will be submitted
disableddisabledSpecifies that an <input> element should be disabled
formform_idSpecifies one or more forms the <input> element belongs to
formactionURLSpecifies the URL of the file that will process the input control when the form is submitted (for type="submit" and type="image")
formenctypeapplication/x-www-form-urlencoded
multipart/form-data
text/plain
Specifies how the form-data should be encoded when submitting it to the server (for type="submit" and type="image")
formmethodget
post
Defines the HTTP method for sending data to the action URL (for type="submit" and type="image")
formnovalidateformnovalidateDefines that form elements should not be validated when submitted
formtarget_blank
_self
_parent
_top
framename
Specifies where to display the response that is received after submitting the form (for type="submit" and type="image")
heightpixelsSpecifies the height of an <input> element (only for type="image")
listdatalist_idRefers to a <datalist> element that contains pre-defined options for an <input> element
maxnumber
date
Specifies the maximum value for an <input> element
maxlengthnumberSpecifies the maximum number of characters allowed in an <input> element
minnumber
date
Specifies a minimum value for an <input> element
multiplemultipleSpecifies that a user can enter more than one value in an <input> element
nametextSpecifies the name of an <input> element
patternregexpSpecifies a regular expression that an <input> element's value is checked against
placeholdertextSpecifies a short hint that describes the expected value of an <input> element
readonlyreadonlySpecifies that an input field is read-only
requiredrequiredSpecifies that an input field must be filled out before submitting the form
sizenumberSpecifies the width, in characters, of an <input> element
srcURLSpecifies the URL of the image to use as a submit button (only for type="image")
stepnumberSpecifies the legal number intervals for an input field
typebutton
checkbox
color
date 
datetime-local 
email 
file
hidden
image
month 
number 
password
radio
range 
reset
search
submit
tel
text
time 
url
week
Specifies the type <input> element to display
valuetextSpecifies the value of an <input> element
 
widthpixelsSpecifies the width of an <input> element (only for type="image")

Global Attributes

The <input> tag also supports the Global Attributes in HTML.

Event Attributes

The <input> tag also supports the Event Attributes in HTML.

Related Pages

HTML tutorial: HTML Forms
HTML DOM reference:

Default CSS Settings

None.

No comments:

Post a Comment