The HTML <input> element is employed to depict a form input control within an HTML document. This input control enables users to enter data and interact with a website or application. For instance, consider an HTML form containing three input fields - two text fields and a button for submitting information.
HTML Input Tag Example
Let's see the example of HTML input tag.
<form action="#">
First name: <input type="text" name="FirstName" placeholder="enter firstname..."><br>
Last name: <input type="text" name="LastName" placeholder="enter lastname..."><br>
<input type="submit" value="Submit">
</form>
Output:
Press the "Submit" button to transmit the form-data to a server-side page.
Points to remember
Utilize the input element inside the form element to define input controls that enable users to input data.
The input element is void of content, housing only attributes. It does not require a closing tag in HTML.
If you wish to specify labels for input elements, utilize the label element in conjunction with each input tag.
Difference between HTML4.01 and HTML5
HTML5 does not facilitate the "align" attribute. There are multiple fresh attributes available for the <input> tag in HTML5, with the type attribute presenting several additional values.
Difference between HTML and XHTML
In HTML, the <input> element is utilized without a closing tag. In XHTML, the <input> element needs to be correctly closed.
Supporting Browsers
| Element | Chrome | IE | Firefox | Opera | Safari |
|---|---|---|---|---|---|
<input> |
Yes | Yes | Yes | Yes | Yes |