Skip to content

<input> - The Input Element

Form Control HTML 2.0

The input element creates interactive controls for web forms to accept data from users. With 22 different types, it’s the most versatile form control in HTML.

Result
<input type="text" name="fieldname">

The <input> element is self-closing (void element) and requires no closing tag.

These attributes work with most input types:

AttributeDescriptionExample
typeSpecifies the input control typetext, email, password, etc.
nameName for the form dataname="username"
valueInitial value of the inputvalue="John"
placeholderHint text shown when emptyplaceholder="Enter email"
requiredMakes field mandatoryrequired
disabledDisables the inputdisabled
readonlyMakes input read-onlyreadonly
autocompleteEnable/disable autocompleteon, off, email, username, etc.
autofocusAuto-focus on page loadautofocus
AttributeDescriptionApplicable Types
patternRegular expression for validationtext, search, tel, url, email
minMinimum valuenumber, range, date, time
maxMaximum valuenumber, range, date, time
minlengthMinimum character lengthtext, search, tel, url, email, password
maxlengthMaximum character lengthtext, search, tel, url, email, password
stepIncrement valuenumber, range, date, time
AttributeDescriptionApplicable Types
acceptFile types to acceptfile
altAlternative textimage
checkedPre-select checkbox/radiocheckbox, radio
multipleAllow multiple valuesemail, file
sizeVisible width in characterstext, search, tel, url, email, password
srcImage URLimage
listID of datalist elementMost text types

Standard single-line text input:

Result

Obscured text input for sensitive data:

Result

Email address input with built-in validation:

Result

URL input with validation:

Result

Telephone number input:

Result

Search field with platform-specific styling:

Result

Numeric input with spinner controls:

Result

Slider control for numeric range:

Result

Date picker:

Result

Time picker:

Result

Date and time picker (local timezone):

Result

Month and year picker:

Result

Week picker:

Result

Toggle option on/off:

Result

Select one option from a group:

Result

File upload control:

Result

Color picker:

Result

Submit button:

Result

Reset button (clears form):

Result

Generic button (no default behavior):

Result

Hidden field (not visible to users):

Result

Image submit button:

Result
Result
Result
Result

The autocomplete attribute helps browsers fill in forms:

Result

Common autocomplete values: name, email, username, new-password, current-password, tel, street-address, postal-code, country, cc-number, cc-exp, etc.

Result
<!-- Explicit association -->
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<!-- Implicit association -->
<label>
Email:
<input type="email" name="email">
</label>
Result
Result
Result
<label for="email">
Email <span aria-label="required">*</span>
</label>
<input type="email" id="email" name="email" required>
Input TypeChromeFirefoxSafariEdge
text, password, checkbox, radio, submit, reset, button, file, hidden, image1+1+1+12+
email, url, tel, search5+4+5+12+
number7+29+5+12+
range5+23+4+12+
date, time, datetime-local20+57+14.1+12+
month, week20+12+
color20+29+12.1+14+