Skip to main content

What does the <input> element do?

The <input> element is the core form element intended for user data entry. It creates an interactive field where you can enter text, pick an option, tick a box, upload a file and much more.

In effect, <input> is a universal "container" for different kinds of user input, determined by the type attribute.


1. General syntax

html
<input type="text" name="username" placeholder="Enter your name">

Here:

  • type="text" sets the field type (plain text in this case);
  • name="username" is the field's name (needed to send data to the server);
  • placeholder="Enter your name" is the hint text inside the field.

2. Main types

Type (type)PurposeExample
textSingle-line text field
passwordPassword field (characters hidden)
emailEmail address entry (checks the format)
numberNumber entry, with up/down arrows
telPhone number entry
urlLink entry (checks the URL format)
searchSearch field (styled by the browser)
checkboxCheckbox (several can be selected)
radioRadio button (only one can be selected)
fileFile upload
dateDate picker
rangeRange slider
colorColor picker
hiddenHidden field (not visible to the user)
submit"Submit form" button
resetResets all form fields
buttonPlain button (for JS handling)

3. Key attributes

AttributePurpose
nameField name (key for sending data)
valueDefault value
placeholderHint inside the field
requiredMakes the field mandatory
readonlyField is read-only
disabledField is disabled (cannot be edited)
maxlengthMaximum number of characters
min / maxMinimum and maximum value (for numbers, dates, etc.)
stepIncrement step (e.g. 0.5)
checkedSets the checkbox/radio as checked by default

4. How it works with a form

If an <input> element is inside a <form> and has a name attribute, then on form submission the browser will send its value as a pair:

javascript
name=value

Example:

html
<form action="/send" method="post"> <input type="text" name="user" value="Oleh"> <input type="checkbox" name="subscribe" checked> <button type="submit">OK</button> </form>

The server will receive:

javascript
user=Oleh&subscribe=on

5. Features

  • <input> is a void tag (it has no </input>).

  • Different <input> types provide different interfaces and validation.

  • It can be combined with <label> for a convenient selection:

    html
    <label> <input type="checkbox"> I agree to the terms </label>

Summary:

PropertyDescription
PurposeGetting data from the user
Typestext, password, email, checkbox, radio, file and others
SendingVia the name attribute on form submit
FeatureVoid, universal, configured via type
PlacementUsually inside a <form>

In simple terms: <input> is a "point of entry" for the user. It turns a static page into an interactive one, letting the site receive information rather than just display it.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.