type=text

FilterElements

HTML: <input type="text">
XHTML: <input type="text"/>  or  <input type="text" />

Creates a text input element. This is the default input type, as well as one of the most useful and common. Text provided for the value attribute will appear in the text control when the form loads.

Start/End Tags

This is an empty element. In HTML, the end tag is forbidden. In XHTML, the element must be closed with a trailing slash as just shown. Developers may include a space character before the slash for backward compatibility with older browsers.

Specifications

  • HTML 4.01
  • HTML5

autocomplete=

Values: on | off
HTML5 only. Allows the user agent (browser) to fill in a field automatically (on) or requires the user to enter the information every time (off). Omitting this attribute causes the control to inherit the autocomplete setting for the associated form element.

autofocus

Values: None in HTML. (autofocus="autofocus" in XHTML)
HTML5 only. Indicates the control should have focus (be highlighted and ready for user input) when the document loads.

disabled

Values: None in HTML. (disabled="disabled" in XHTML)
Disables the control for user input. It can be altered only via a script. Browsers may display disabled controls differently (grayed out, for example), which could be useful for dimming certain controls until required info is supplied.

form=

Values: id of the form owner
HTML5 only. Explicitly associates the input control with its associated form (its form owner). With this method, the input control does not need to be a child of the applicable form element.

list=

Values: id of datalist
HTML5 only. Indicates that the control has a list of predefined suggestions for the user, which are provided by a datalist element. The value of the list attribute is the id of the associated datalist.

maxlength=

Values: number
Specifies the maximum number of characters the user can enter for input elements set to text, password, search, tel, or url.

name=

Values: text
Required. Assigns a name to the control; a script program uses this name to reference the control.

pattern=

Values: JavaScript regular expression
HTML5 only. Specifies a regular expression against which the control’s value is to be checked. This is useful for making sure user input matches the format of the expected value, for example, a telephone number or an email address. The title attribute can be used with pattern to provide a description of the expected pattern/format of the input.

placeholder=

Values: number
HTML5 only. Provides a short (one word or short phrase) hint or example to help the user enter the correct data or format. If a longer description is necessary, use the title attribute.

readonly

Values: None in HTML. (readonly="readonly" in XHTML)
Indicates that the form input may not be modified by the user.

required

Values: None in HTML. (required="required" in XHTML)
HTML5 only. When present, indicates the input value is required.

size=

Values: number
Specifies the width of a text-entry control (when type is set to text, password, or search), measured in number of characters. Users may type entries that are longer than the space provided, causing the field to scroll to the right.

value=

Values: text
Specifies the initial value for this control.

HTML 4.01 <input> Events

onchange
Occurs when the element loses the input focus and its value has been modified since gaining focus
onselect
Occurs when text within the element is selected
<input type="text" name="name" size="15" maxlength="50" value="enter your name">

Rendered Example