Input HTML

HTML <input> Tag

The HTML <input> tag is used in an HTML form, in which the “type” attribute is used to define the different types of the information field. The HTML <input> tag is used to specify an input control to create form fields and to take inputs from the user. It is a fundamental form element in HTML. Different input fields can be applied to gather different information from the site visitors.

Example 1: To create a one-line text input field.

<!DOCTYPE html>
<html>
<body>
<h4>Fill the Form:</h4>
<form action="/action_page.php">
User Name: <input type="text" name="UserName" value="Joy"><br><br>
City: <input type="text" name="City" value="Jaipur"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Explanation:

In the above example, we created two one-line text input fields.

Example 2: To define a one-line password input field.

<!DOCTYPE html>
<html>
<body>
<h4>Fill the Form:</h4>
<form action="/action_page.php">
User Name: <input type="text" name="UserName" value="Joy"><br><br>
New Password: <input type="password" name="password" value="password"/><br><br>  
<input type="submit" value="Submit">
</form>
</body>
</html>

Explanation:

In the above example, we created a one-line text input field and a password field in HTML.

HTML 4.01 and HTML 5:

Several new attributes are introduced for the <input> tag in HTML5. The “align” attribute is removed from HTML5. Also, in HTML 5, several new values are introduced for the type attribute.

HTML and XHTML:

The HTML <input> tag does not require an end tag. The XHTML <input> tag, however, requires the closing tag.

Global Attributes:

The HTML GLobal attributes are supported by the HTML <input> tag.

Event Attributes:

The HTML Event attributes are supported by the HTML <input> tag.

Supporting Browsers:

Chrome, IE, Firefox, Opera, and Safari.