Skip to content

HTML Tutorial Forms

The HTML input Element: Text Fields and Common Attributes

Lesson 45 of 81 2 min read By Deepak Paswan Updated Oct 4, 2026

input is a single element that becomes many different controls depending on its type. It is an empty element.

index.html
HTML
<form>
  <label for="name">Your name</label>
  <input type="text" id="name" name="name" placeholder="Asha Verma" required>
</form>

Key attributes

AttributePurpose
typeWhat kind of control it is (default text)
nameThe name sent with the value
idConnects the field to its label
valueThe starting value
placeholderA hint shown while the field is empty
requiredThe field must be filled in
disabledThe field cannot be used or sent
readonlyThe value can be seen and sent, but not changed
autocompleteHelps the browser fill the field in
index.html
HTML
<form>
  <label for="city">City</label>
  <input type="text" id="city" name="city" value="Hillford" readonly>

  <label for="code">Gift code</label>
  <input type="text" id="code" name="code" maxlength="8" autocomplete="off">
</form>

Placeholders are not labels

A placeholder disappears as soon as the visitor starts typing, and often has poor contrast. Always provide a real label too, as shown in HTML Labels.

warning
Using disabled when you mean readonly
A disabled field is not sent with the form. If the server needs the value, use readonly.