Introduction
<input> tag is used to specify/display the input field, where users can provide some input in the web page.
There are different types of input types which are as follows -
- button
- checkbox
- color
- date
- datetime-local
- file
- hidden
- image
- month
- number
- password
- radio
- range
- reset
- search
- submit
- tel
- text
- time
- url
- week
The type is defined as an attribute in the <input /> tag.
<input type="text" />
Output
- button
<input type="button" value="submit" /> - checkbox
<input type="checkbox" /> - color
<input type="color" /> - date
<input type="date" /> - datetime-local
<input type="datetime-local" /> - email
<input type="email" /> - file
<input type="file" /> - hidden
<input type="hidden" /> - image
<input type="image" src="https://common-content.thegyanva.com/images/logo.png" /> - month
<input type="month" /> - number
<input type="number" /> - password
<input type="password" /> - radio
<input type="radio" /> - range
<input type="range" /> - reset
<input type="reset" /> - search
<input type="search" /> - submit
<input type="submit" /> - tel
<input type="tel" /> - text
<input type="text" /> - time
<input type="time" /> - url
<input type="url" /> - week
<input type="week" />
The mentioned list is the code and output example of different types of input tags.
Attributes
accept | file types like audio/*, video/* for only type="file" |
alt | alternate text for type="image" |
autocomplete | on/off |
autofocus | for input element to automatically focus on page load |
checked | for type="checkbox" and type="radio" |
disabled | to diable the element |
form | id of the form to which the input belongs |
maxlength | maximum number of characters allowed in the input |
minlength | minimum number of characters allowed in the input |
name | name of the element |
pattern | regexp - regular expression for input matching |
placeholder | short hint to specify the element's expectation |
readonly | for making the element read only |
required | makes the element required before submitting the form |
src | url of the image. Only for type="image" |
type | type of element as shown in the above section |
value | value of the input |