HTML <input> Tag

Description:

The <input> tag is used within a form to declare an input element - a control that allows the user to input data.

 

Specific Attributes:

Attribute Definition
type Specifies the type of control.
Possible values:
  • text
  • password
  • checkbox
  • radio
  • submit
  • reset
  • file
  • hidden
  • image
  • button
name Assigns a name to the input control.
value Specifies the value of an input element
size Specifies the width of an input field
maxlength Specifies the maximum length (in characters) of an input field (for type="text" or type="password")
checked If type="radio" or type="checkbox" it will already be selected when the page loads.
src If type="image", this attribute specifies the location of the image.

Other Attributes:

Attribute Definition
dir

Specifies the text direction for the content in an element.
Possible Values:

  • rtl  (Right to Left)
  • ltr  (Left to Right)
class Specifies a classname for an element.
id Specifies a unique id for an element.
lang Specifies a language code for the content in an element.
title Specifies a title to associate with the element. Many browsers will display this when the cursor hovers over the element (similar to a "tool tip").
style Specifies an inline style for an element.
align For alignment (left, center, right, justify).
alt Alternate text. This specifies text to be used in case the browser/user agent can't render the input control.
accept Specifies a comma-separated list of content types that the server accepts.
readonly Sets the input control to read-only - it won't allow the user to change the value. The control however, can receive focus and are included when tabbing through the form controls.
disabled Disables the input control. The button won't accept changes from the user. It also cannot receive focus and will be skipped when tabbing.
tabindex Specifies the tab order of an element.
accesskey Specifies a keyboard shortcut to access an element.

Example Code:

<form action="" method="post">
  First name: <input type="text" name="first_name" /><br />
  Last name: <input type="text" name="last_name" /><br />
  <input type="submit" value="Submit" />
</form>

Result
  First name:
  Last name: