input (type=email) element

If you don't know what an element is or how you must use it, I recommend you read the "HTML tags and attributes" tutorial that you can find in the HTML tutorials section.

Description

The input element, having the "email" value in its type attribute, represents a field for one or more e-mail addresses. When the multiple attribute is present, the control can take a list of comma-separated e-mail addresses.

The control associated to this field is, when set as a single e-mail input, a text box that allows users to edit only one line of plain text. But when the multiple attribute is present, browsers should provide the means for users to add, edit and remove any number of e-mail addresses.

Browsers, aware of the type of data this field should receive, may provide autocompletion options based on contact lists saved in the user's computer.

Browsers may perform some kind of validation on e-mail inputs. In such cases, the pattern attribute may be used to perform a second check after the standard validation, allowing authors to set further restrictions.

Browser support for e-mail inputs is incomplete. Authors may need to rely on client-side scripts to provide extra functionality for this type of fields, until support grows.

Examples

In our first example we'll create a form with a single e-mail address input. Here, we'll make use of the placeholder attribute, which has been introduced in HTML5. This attribute allows us to give a hint about the data that's expected to be provided in the control, like examples or short descriptions. This hint will be displayed inside the control (as if it were the value) only while the control has no real value. When the user starts typing, the placeholder text will be removed from the control.

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail address: <input type="email" name="emailaddress" placeholder="e.g. user@server.com">
    <input type="submit" value="Send data">
  </p>
</form>

E-mail address:

Now we'll use the value attribute to provide the control with an initial value, that will be set when the page loads and when the reset button is pressed. Here we'll use it to show a value the user has already entered in a previous form.

<form action="../../form-result.php" method="post" target="_blank">
  <p>E-mail address: <input type="email" name="emailaddress" value="superuser138@yahoo.com"></p>
  <p>
    <input type="submit" value="Send data">
    <input type="reset" value="Reset form">
  </p>
</form>

E-mail address:

In our third example we're using the attribute multiple, which allows users to input any number of e-mail addresses. Browsers are supposed to provide an interface to allow users to add, edit and remove e-mail addresses from the control, but most of them provides just a text box with conformance check for a list of comma-separated e-mail addresses.

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail addresses: <input type="email" name="emails" multiple>
    <input type="submit" value="Send data">
  </p>
</form>

E-mail addresses:

Our final example combines two attributes, also new in HTML5, that usually work well together. These are pattern and required. Their importance becomes evident when the author needs to set rules about the format of data that can be input in a control.

The pattern attribute, helps by estabishing a regular expression that any input value must comply with. When it's set, the title attribute takes particular relevance, as it's responsible of providing an explanation about the rules that apply on the field. Browsers may use this information to compose the error message shown to the user after an unsuccessful submission.

In the other hand, the required attribute disallows users to leave the field empty. Both attributes, together, indicate that the control must be filled and specify how it must be filled.

A regular expression is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings or search-and-replace like operations.

Browser support for the attribute required is incomplete. Authors may have to rely on scripts to provide this functionality cross-browser.

Browsers may perform some kind of validation on e-mail inputs. In such cases, the pattern attribute may be used to perform a second check after the standard validation, allowing authors to set further restrictions.

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    MailForAll.com address: <input type="email" name="emailaddress" pattern=".+@[mM][aA][iI][lL][fF][oO][rR][aA][lL][lL][.][cC][oO][mM]" title="Only MailForAll.com accounts are allowed">
    <input type="submit" value="Send data">
  </p>
</form>

MailForAll.com address:

Attributes

Specific attributes

autocomplete

The autocomplete attribute provides information about if and how browsers should automatically suggest options for this control, as an attempt to guess what the user is typing. There are three possible values for this attribute:

  • The value on value, indicating the browser that it should suggest options automatically but not providing any further information about what kind of data is expected in the control.
  • The value off, indicating the browser that it shouldn't suggest options automatically, either because the control's input data is particularly sensitive (like the user to login in a very secure area) or because it's a value that will never be reused (like a one-time-key in a registration process).
  • An autofill detail tokens list, indicating the browser that it should suggest options automatically and specifying what kind of value is expected.

An autofill detail tokens list can be composed by the following tokens in the specified order.

  1. Optionally, a token beginning with the string "section-" (case-insentsitive), indicating the named group to which the field belongs.
  2. Optionally, one of the two following tokens (case-insentsitive):
    • shipping: the field is part of the shipping address.
    • billing: the field is part of the billing address.
  3. The following, in the given order:
    1. Optionally, a token that is a case-insensitive match for one of the following strings:
      • home: meaning the field is for contacting someone at their residence.
      • work: meaning the field is for contacting someone at their workplace.
      • mobile: meaning the field is for contacting someone at their mobile device.
      • fax: meaning the field describes a fax machine's contact details.
      • pager: meaning the field describes a pager's or beeper's contact details
    2. A token that is a case-insensitive match for the following autofill field name:
      • email: an email address, like jhondoe@unknown.com.

Browsers usually perform autofilling operations by retrieving data from a database containing previous inputs or other sources of user information.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Work e-mail: <input type="email" name="workemail" autocomplete="work email">
    <input type="submit" value="Send">
  </p>
</form>

Work e-mail:

autofocus

A boolean value instructing the browser to set the focus to this control when the document has finished loading or when the dialog where the control finds itself is shown. If the attribute has the value "autofocus" or the empty string (""), or if it's just present, the control should get the focus as soon as possible, after the page or dialog has been loaded.

Example

<p>E-mail address: <input type="email" name="emailaddress" autofocus></p>

disabled

A boolean value indicating wether the control is disabled or not. If the attribute takes the value "disabled" or the empty string (""), or if it's just present, the control will be disabled.

Disabled controls are rendered greyed out (if visible), are blocked from user interaction and, more importantly, their values (if any) aren't sent when the form is submitted.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Referer e-mail: <input type="email" name="refereremail" value="jhon@yahoo.com" disabled>
    <input type="submit" value="Send data">
  </p>
</form>

Referer e-mail:

form

The value of the id attribute of the form with which this control is associated to.

This attribute is new in HTML5 and helps defining the pertenence of controls in nested or distant forms.

Example

<p>E-mail: <input type="email" name="emailaddress" form="form1"></p>
<form id="form1" action="../../form-result.php" method="post" target="_blank">
  <p><input type="submit" value="Send data"></p>
</form>

E-mail:

list

A token matching the value of the id attribute of the datalist this control is assopciated with. The datalist referenced by this attribute will provide a number of suggestions that users can pick to autocomplete the control.

Browser support for datalist is incomplete. Authors may have to rely on scripts to provide this functionality cross-browser.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Contacted address: <input type="email" name="contactedaddress" list="emailslist">
    <input type="submit" value="Send data">
  </p>
</form>
<datalist id="emailslist">
  <option value="info@supermegaco.com">
  <option value="sales@supermegaco.com">
  <option value="jhonsmith@supermegaco.com">
  <option value="alansmith@supermegaco.com">
</datalist>

Contacted address:

maxlength

An integer indicating the maximum number of characters the value of this control may have.

Authors shouldn't rely on the maxlength attribute. Users can always submit the form with browsers (some intentionally) not supporting this feature.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail: <input type="email" name="emailaddress" maxlength="30">
    <input type="submit" value="Send data">
  </p>
</form>

E-mail:

minlength

An integer indicating the minimum number of characters the value of this control may have.

Authors shouldn't rely on the minlength attribute. Users can always submit the form with browsers (some intentionally) not supporting this feature.

Browser support for the minlength attribute is extremely low (as of 2014/12/18). Authors shouldn't rely on this attribute until support grows.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail: <input type="email" name="emailaddress" minlength="8">
    <input type="submit" value="Send data">
  </p>
</form>

E-mail:

multiple

A boolean value indicating wether the control should accept multiple values or not. If the value in this attribute is "multiple" or the empty string (""), or if the attribute is just present, the control is supposed to take multiple values.

Browsers are supposed to provide an interface to allow users to add, edit and remove e-mail addresses from the control, but most of them provides just a text box with conformance check for a list of comma-separated e-mail addresses.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail addresses: <input type="email" name="emails" multiple>
    <input type="submit" value="Send data">
  </p>
</form>

E-mail addresses:

name

A name for the control. This name will be sent by the browser to the processing agent, paired with the content of the value attribute. Both attributes together will conform a name-value pair that will be used to process the form data.

Currently, the value isindex, formerly used in a special way by some browsers and included in the HTML standard, isn't permitted in this attribute.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    New e-mail: <input type="email" name="newemail">
    <input type="submit" value="Send data">
  </p>
</form>

New e-mail:

pattern

A regular expression to match against the control's value before the form is submitted. This attribute can be used to specify a format that users will have to comply with when filling the field. If this pattern isn't respected, an error message will be shown upon submission and the process will be cancelled (unless the formnovalidate attribute is present in the form or submission button).

The title attribute takes a special meaning when this attribute is present: it's expected to provide an explanation about the rules that apply on the field. Browsers may use the information in title to compose the error message shown to the user when the process of submission is cancelled.

A regular expression is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings or search-and-replace like operations.

Browsers could perform some kind of validation on e-mail inputs. In such cases, the pattern attribute may be used to perform a second check after the standard validation, allowing authors to set further restrictions.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail (.com servers only): <input type="email" name="emailaddress" pattern=".+\.com" title="Only well formed e-mail addresses belonging to .com servers are accepted">
    <input type="submit" value="Send data">
  </p>
</form>

E-mail (.com servers only):

placeholder

A run of text that's supposed to provide a hint about how the field should be filled in, like examples or short descriptions. Browsers may display the contents of this attribute in the control while it has no value. As soon as users start to write down their own text, the placeholder text should dissapear from the control.

Authors shouldn't use this attribute to replace the label. Labels are suposed to provde a title, while the placeholder should give a small hint about how to fill the field. Morover, the placeholder text is expected to disapear when the user starts typing in the control.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail: <input type="email" name="emailaddress" placeholder="user@server.com">
    <input type="submit" value="Send data">
  </p>
</form>

E-mail:

readonly

A boolean value instructing the browser to prevent the user from changing the control's value. If this attribute has the value "readonly" or the empty string (""), or if it's just present, the user won't be allowed to change the value in the control.

Although this attribute prevents the control's value from being edited, not all interaction is blocked: users will still be able to select and copy the text in the control.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    Work e-mail: <input type="email" name="workemail" value="jhon@supermegaco.com" readonly>
    <input type="submit" value="Send data">
  </p>
</form>

Work e-mail:

required

A boolean value indicating wether this control can be left empty or not. If this attribute has the value "required" or the empty string (""), or if it's just present, the user will have to fill the control in order to be able to submit the form.

If a control with the required attribute present is left blank, supporting browsers will throw an error upon submission and cancel the process immediately.

Browser support for the attribute required is incomplete. Authors may have to rely on scripts to provide this functionality cross-browser.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    E-mail: <input type="email" name="emailaddress" required>
    <input type="submit" value="Send data">
  </p>
</form>

E-mail:

size

An integer to use as width of the element, in number of characters that should be visible in the control simultaneously.

As characters usually don't have the same width, browsers may define a character witdth according to certain criteria (like average or maximum width).

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>
    New e-mail: <input type="email" name="newemail" size="20">
    <input type="submit" value="Send data">
  </p>
</form>

New e-mail:

type

A value indicating the type of the field that this element represents. There are twenty two possible values (case-insensitive):

  • hidden: a hidden control used to send information to the server, typically managed by scripts.
  • text: a control used to input a single-line piece of text.
  • search: same as text but for search purposes.
  • tel: a control used to provide a telephone number.
  • url: a text box used to input a single and absolute URL.
  • email: a control designed to edit one or more e-mail addresses.
  • password: a text box for editing passwords, where the characters are represented by dots.
  • date: a control to input a specific date.
  • month: a control to input a specific month.
  • week: a control to input a specific week.
  • time: a control to input a specific time.
  • datetime-local: a control to input a specific local date and time.
  • number: a control to input a number.
  • range: a control to input one or two numbers inside a range.
  • color: a control to input a color.
  • checkbox: a control to input a boolean value (true/false).
  • radio: a control used to choose one single option among many.
  • file: a control used to upload files to the server.
  • submit: a button used to submit the form.
  • image: same as submit but with the ability to be shown as an image instead of using the default button appearance.
  • reset: a button used to reset the form's controls to their default values.
  • button: a button with no default action associated.

When this attribute isn't present, the element behaves as it would have the value "text".

Example

<input type="email" name="emailaddress">

value

An initial value for the control, that will be set when the page loads and when the reset button is pressed.

Example

<form action="../../form-result.php" method="post" target="_blank">
  <p>Work e-mail: <input type="email" name="workemail" value="jhon@supermegaco.com"></p>
  <p>
    <input type="submit" value="Send data">
    <input type="reset" value="Reset form">
  <p>
</form>

Work e-mail:

Global attributes

For information about global attributes refer to this list of global attributes in HTML5.

Events

Global events

For information about global events refer to this list of global events in HTML5.