HTML Input Attributes

This chapter describes the different attributes for the HTML <input> element.

The value Attribute

The input value attribute specifies an initial value for an input field:

Example

Input fields with initial (default) values:

<form>
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John"><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe">
</form>

Input read-only attribute specifies that input field is read-only.

Input-only input field cannot be changed (however, the user can table it, highlight it, and copy text to it).

The input field for read-only field will be sent when the form is submitted!

Example

A read-only input field:

<form>
  <label for="fname">First name:</label><br>
  <input type="text" id="fname" name="fname" value="John" readonly><br>
  <label for="lname">Last name:</label><br>
  <input type="text" id="lname" name="lname" value="Doe">
</form>