HTML input Tag

The HTML <input> tag is used to represent a form input control in an HTML document. This tag is used within a form and the form allows the user to input data and interacts with a website or application. The <Input> tag is an empty element that contains only attributes.

Syntax

<input type="value" />

Example

<!DOCTYPE html>
<html>
   <head>
      <title>HTML input Tag</title>
   </head>
   <body>
      <form action = "#" >
         First Name: 
         <input type="text" name="fname" />
         <br />
         Last Name: 
         <input type="text" name="lname" /><br>
         <input type="submit" value="Submit" />
      </form>
   </body>
</html>

Output:

HTML input Tag

Attributes

Attribute Value Description
accept audio/*
video/*
image/*
MIME_type
Specifies the types of files you can send via the file upload field. ( only for type=”file”)
align left
right
top
middle
bottom
Specifies the alignment of the image. (only for image)
alt text Specifies the alternate text for the image.
autocomplete on

off

Specifies whether to enable autocomplete in the input element on or off.
autofocus autofocus Specifies that the input element should be automatically focused when the page is loaded.
checked checked Specifies that the element should be re-selected when the page is loaded. ( for type=”checkbox” or type=”radio”)
disabled disabled It is used to disable the input element.
form form_id Specifies one or more forms
formaction Specifies the URL where the form data will be sent when clicking on the button. (for type=”submit” and type=”image”)
formenctype application/x-www-form-urlencoded
multipart/form-data
text/plain
Specifies how the form data should be encoded when submitting it on the server. ( for type=”submit” and type=”image”)
formmethod get
post
Specifies the HTTP method for sending data to the action URL. (for type=”submit” and type=”image”)
formnovalidate formnovalidate Specifies that the form elements should not be validated when submitted.
formtarget _blank
_self
_parent
_top
framename
Specifies where to display the response after submitting the form. (for type=”submit” and type=”image”)
height pixels Specifies the height of an element (only for type=”image”)
list datalist_id Specifies the <datalist> element that contains pre-defined options for an <input> element.
max number
date
Specifies the maximum value of the input element.
maxlength number Specifies the maximum number of characters allowed in a text field.
min number
date
Specifies the minimum value of the input element.
minlength number Specifies the minimum number of characters allowed in a text field.
multiple multiple Specifies that a user can enter multiple values on the input element.
name text Specifies the name of an input element.
pattern regexp Specifies a regular expression that an <input> element’s value is checked against.
placeholder text Specifies the short hint that describes the expected value.
readonly readonly Specifies that the input field is read-only.
required required Specifies that an input field must be filled out before submitting the form.
size number Specifies the width in characters of an <input> element.

 

src URL Specifies the URL of the image to use as a submit button.
(only for type=”image”)
steps number Specifies the legal number intervals in an input field.
type button
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 of input element.
value text Specifies the value of an input element.
width pixels Specifies the width of an element.c (only for type=”image”)

Global Attributes

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

Event Attributes

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

Supported Browsers

Element Chrome Firefox IE Opera Safari
<input Yes Yes Yes Yes Yes

Leave a Comment

Your email address will not be published.