Last Updated : 11 Jul, 2025
The <input> tag in HTML is used to collect user input in web forms. It supports various input types such as text, password, checkboxes, radio buttons, and more.
An input field can be of various types depending upon the attribute type. The Input tag is an empty element that only contains attributes. For defining labels for the input element, <label> can be used.
Note: The <input> Tag supports the Global Attributes & the Event Attributes in HTML.
Syntax<input type = "value" ... />index.html
<html>
<body>
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</form>
</body>
</html>
Code Overview:
The <label> element with the for attribute associates the label "Username:" with the <input> field, enhancing accessibility.
The <input> element of type "text" creates a single-line text input field where users can enter their username.
Attributes
Descriptions
It is used to specify the type of the input element. Its default value is text.
It is used to specify the value of the input element.
Placeholder attribute is used to specify hint that describes the expected value of an input field.
It is used to specify the name of the input element.
It is used to provide alternate text for the user, if they cannot view the image.
It specifies that an element should automatically get focus when the page loads.
It specifies that an element should be pre-selected (checked) when the page loads.
The disabled attribute specifies that the element should be disabled
The form attribute is used to specify one or more forms to which the <input> element belongs to.
It is used to specify the maximum value for an < input > element.
It specifies that an input field must be filled out before submitting the form.
It specifies that an input field is read-only. A read-only input field cannot be modified.
It is used to specifies the types of files that the server accepts.
It is used to specifies the alignment of an image input.
It s used to specifies whether an <input> element should have autocomplete enabled
It is used to specifies that the text direction will be submitted.
It is used to specifies the URL of the file that will process the input control when the form is submitted
It is used to specifies how the form-data should be encoded when submitting it to the server
It is used to defines the HTTP method for sending data to the action URL
It is used to defines that form elements should not be validated when submitted
It is used to specifies where to display the response that is received after submitting the form
It is used to specifies the height of an <input> element
It is used to refers to a <datalist> element that contains pre-defined options for an <input> element
It is used to specifies the maximum number of characters allowed in an <input> element
It is used to specifies a minimum value for an <input> element
It is used to specifies that a user can enter more than one value in an <input> element
It is used to specifies a regular expression that an <input> element's value is checked against
It is used to specifies the width, in characters, of an <input> element
It is used to specifies the URL of the image to use as a submit button
It is used to specifies the legal number intervals for an input field
It is used to specifies the width of an <input> element (only Ifor type="image")
More Examples of HTML input tag
Styled Password Input Field index.html
<html>
<head>
<style>
input[type="password"] {
border: 2px solid #4CAF50;
border-radius: 4px;
padding: 10px;
width: 200px;
}
</style>
</head>
<body>
<form>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
</form>
</body>
</html>
Code Overview:
<html>
<head>
<style>
input[type="email"] {
border: 1px solid #ccc;
padding: 8px;
font-size: 14px;
width: 250px;
}
</style>
</head>
<body>
<form>
<label for="email">Email:</label>
<input type="email" id="email" name="email"
placeholder="example@example.com">
</form>
</body>
</html>
Code Overview:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4