<input> elements of type
"email" are used to let the user enter and edit an email address, or, if the
multiple attribute is specified, a list of email addresses. The input value is automatically validated to ensure that it's either empty or a properly-formatted email address (or list of addresses) before the form can be submitted. The
:invalid CSS pseudo-classes are automatically applied as appropriate.
Browsers that don't support type
"email" fall back to being a standard
<input id="emailAddress" type="email">
|Supported Common Attributes||
value attribute's value contains a
DOMString which is automatically validated as conforming to email syntax. More specifically, there are three possible value formats that will pass validation:
"firstname.lastname@example.org". There's more to it than that, of course; see Validation for a
regexpthat matches the email address validation algorithm.
multipleattribute is specified, the value can be a list of properly-formed email addresses separated by commas. Any trailing and leading whitespace is removed from each address in the list.
See Validation for details on how email addresses are validated to ensure that they're formatted properly.
Email addresses are among the most frequently-input textual data forms on the web; they're used when logging into web sites, when requesting information, to allow order confirmation, for webmail, and so forth. As such, the
"email" input type can make your job as a web developer much simpler, since it can help simplify your work when building the user interface and logic for email addresses. When you create an email input with the proper
"email", you get automatic validation that the entered text is at least in the correct form to potentially be a legitimate email address. This can help avoid cases in which the user mistypes their address, or provides an invalid address.
It's important, however, to note that this is not enough to ensure that the specified text is an email address which actually exists, corresponds to the user of the site, or is acceptable in any other way. It simply ensures that the value of the field is properly formatted to be an email address.
It's also crucial to remember that a user can tinker with your HTML behind the scenes, so your site must not use this validation for any security purposes. You must verify the email address on the server side of any transaction in which the provided text may have any security implications of any kind.
Currently, all browsers which implement this element implement it as a standard text input field with basic validation features. The specification does, however, allow browsers latitude on this. For example, the element could be integrated with the user's device's built-in address book to allow picking email addresses from that list. As such, in its most basic form, an email input can be implemented like this:
<input id="emailAddress" type="email">
Notice that it's considered valid when empty and when a single validly-formatted email address is entered, but is otherwise not considered valid. By adding the
required attribute, only validly-formed email addresses are allowed; the input is no longer considered valid when empty.
By adding the
multiple Boolean attribute, the input can be configured to accept multiple email addresses.
<input id="emailAddress" type="email" multiple>
Now, the input is considered valid when a single email address is entered, or when any number of email addresses separated by commas and, optionally, some number of whitespace characters are present.
"multiple" is used, the value is allowed to be empty.
Some examples of valid strings when
"multiple" is specified:
These are some examples of invalid strings:
Sometimes it's helpful to offer an in-context hint as to what form the input data should take. This can be especially important if the page design doesn't offer descriptive labels for each
<input>. This is where placeholders come in. A placeholder is a value that demonstrates the form the
value should take by presenting an example of a valid value, which is displayed inside the edit box when the element's
"". Once data is entered into the box, the placeholder disappears; if the box is emptied, the placeholder reappears.
Here, we have an
"email" input with the placeholder
"email@example.com". Note how the placeholder disappears and reappears as you manipulate the contents of the edit field.
<input type="email" placeholder="firstname.lastname@example.org">
You can control not only the physical length of the input box, but also the minimum and maximum lengths allowed for the input text itself.
The physical size of the input box can be controlled using the
size attribute. With it, you can specify the number of characters the input box can display at a time. In this example, for instance, the email edit box is 15 characters wide:
<input type="email" size="15">
size is separate from the length limitation on the entered email address itself so that you can have fields fit in a small space while still allowing longer email address strings to be entered. You can specify a minimum length, in characters, for the entered email address using the
minlength attribute; similarly, use
maxlength to set the maximum length of the entered email address.
The example below creates a 32-character wide email address entry box, requiring that the contents be no shorter than 3 characters and no longer than 64 characters.
<input type="email" size="32" minlength="3" maxlength="64">
As always, you can provide a default value for an
"email" input box by setting its
<input type="email" value="email@example.com"
Taking it a step farther, can provide a list of default options from which the user can select by specifying the
list attribute. This doesn't limit the user to those options, but does allow them to select commonly-used email addresses more quickly. This also offers hints to
list attribute specifies the ID of a
<datalist>, which in turn contains one
<option> element per suggested value; each
value is the corresponding suggested value for the email entry box.
<input type="email" size="40" list="defaultEmails"> <datalist id="defaultEmails"> <option value="firstname.lastname@example.org"> <option value="email@example.com"> <option value="firstname.lastname@example.org"> <option value="email@example.com"> <option value="firstname.lastname@example.org"> </datalist>
<datalist> element and its
<option>s in place, the browser will offer the specified values as potential values for the email address; this is typically presented as a popup or drop-down menu containing the suggestions. While the specific user experience may vary from one browser to another, typically clicking in the edit box presents a drop-down of the suggested email addresses. Then, as the user types, the list is adjusted to show only matching values. Each typed character narrows down the list until the user makes a selection or types a custom value.
There are two levels of content validation available for
"email" inputs. First, there's the standard level of validation which is offered to all
<input>s, which automatically ensures that the contents meet the requirements to be a valid email address. But there's also the option to add additional filtering to ensure that your own specialized needs are met, if you have any.
HTML form validation is not a substitute for scripts that ensure that the entered data is in the proper format. It's far too easy for someone to make adjustments to the HTML that allow them to bypass the validation, or to remove it entirely. It's also possible for someone to simply bypass your HTML entirely and submit the data directly to your server. If your server-side code fails to validate the data it receives, disaster could strike when improperly-formatted data (or data which is too large, is of the wrong type, and so forth).
Browsers that support the
"email" input type automatically provide validation to ensure that only text that matches the standard format for Internet email addresses is entered into the input box. Browsers that implement the specification should be using an algorithm equivalent to the following regular expression:
There are known specification issues related to international domain names and the validation of email addresses in HTML. See W3C bug 15489 for details.
If you need the entered email address to be restricted further than just "any string that looks like an email address," you can use the
pattern attribute to specify a regular expression the value must match for the value to be valid. If the
multiple attribute is specified, each individual item in the comma-delineated list of values must match the
For example, let's say you're building a page for employees of Best Startup Ever, Inc. which will let them contact their IT department for help. In our simplified form, the user needs to enter their email address and a message describing the problem they need help with. We want to ensure that not only does the user provide a valid email address, but for security purposes, we require that the address be an internal corporate email address.
Since inputs of type
"email" validate against both the standard email address validation and the specified
pattern, you can implement this easily. Let's see how:
<form> <div class="emailBox"> <label for="emailAddress">Your email address</label><br> <input id="emailAddress" type="email" size="64" maxLength="64" required placeholder="email@example.com" pattern=".+@beststartupever.com" title="Please provide only a Best Startup Ever corporate email address"> </div> <div class="messageBox"> <label for="message">Request</label><br> <textarea id="message" cols="80" rows="8" required placeholder="My shoes are too tight, and I have forgotten how to dance."></textarea> </div> <input type="submit" value="Send Request"> </form>
<form> contains one
<input> of type
"email" for the user's email address, a
<textarea> to enter their message for IT into, and an
<input> of type
"submit", which creates a button to submit the form. Each text entry box has a
<label> associated with it to let the user know what's expected of them.
Let's take a closer look at the email address entry box. Its
maxlength attributes are both set to 64 in order to show room for 64 characters worth of email address, and to limit the number of characters actually entered to a maximum of 64. The
required attribute is specified, making it mandatory that a valid email address be provided.
placeholder is provided—
"firstname.lastname@example.org"—to demonstrate what constitutes a valid entry. This string demonstrates both that an email address should be entered, and suggests that it should be a corporate beststartupever.com account. This is in addition to the fact that using type
"email" will validate the text to ensure that it's formatted like an email address. If the text in the input box isn't an email address, you'll get an error message that looks something like this:
If we left things at that, we would at least be validating on legitimate email addresses. But we want to go one step farther: we want to make sure that the email address is in fact in the form "email@example.com". This is where we'll use
pattern. We set
".+@beststartupever.com". This simple regular expression requests a string that consists of at least one character of any kind, then an "@" followed by the domain name "beststartupever.com".
Note that this is not even close to an adequate filter for valid email addresses; it would allow things such as " @beststartupever.com" (note the leading space) or "@@beststartupever.com", neither of which is valid. However, the browser runs both the standard email address filter and our custom pattern against the specified text. As a result, we wind up with a validation which says "make sure this is a valid email address, and if it is, make sure it's also a beststartupever.com address."
It's advisable to use the
title attribute along with
pattern. If you do, the
title must describe the pattern. That is, it should explain what format the data should take on, rather than any other information. That's because the
title may be displayed or spoken as part of a validation error message. For example, the browser might present the message "The entered text doesn't match the required pattern." followed by your specified
title. If your
title is something like "Email address", the result would be the message "The entered text doesn't match the required pattern. Email address", which isn't very good.
That's why, instead, we specify the string "Please provide only a Best Startup Ever corporate email address" By doing that, the resulting full error message might be something like "The entered text doesn't match the required pattern. Please provide only a Best Startup Ever corporate email address."
If you run into trouble while writing your validation regular expressions, and they're not working properly, check your browser's console; there may be helpful error messages there to aid you in solving the problem.
Here we have an email input with the ID
"emailAddress" which is allowed to be up to a maximum of 256 characters long. The input box itself is physically 64 characters wide, and displays the text
"firstname.lastname@example.org" as a placeholder anytime the field is empty. In addition, by using the
multiple attribute, the box is configured to allow the user to enter zero or more email addresses, separated by commas, as described in Allowing multiple email addresses. As a final touch, the
list attribute is used to specify the ID of a
<option>s specify a set of suggested values the user can choose from.
As an added touch, the
<label> element is used to establish a label for the email entry box, with its
for attribute referencing the
"emailAddress" ID of the
<input> element. By associating the two elements in this way, clicking on the label will focus the input element.
<label for="emailAddress">Email</label><br/> <input id="emailAddress" type="email" placeholder="email@example.com" list="defaultEmails" size="64" maxlength="256" multiple> <datalist id="defaultEmails"> <option value="firstname.lastname@example.org"> <option value="email@example.com"> <option value="firstname.lastname@example.org"> <option value="email@example.com"> <option value="firstname.lastname@example.org"> </datalist>
|WHATWG HTML Living Standard |
The definition of '<input type="email">' in that specification.
|Living Standard||Initial definition|
|HTML 5.1 |
The definition of '<input type="email">' in that specification.
|Feature||Chrome||Edge||Firefox (Gecko)||Internet Explorer||Opera||Safari|
|Basic support||5.0||?||Unknown (4.0)||10||10.62||?|
|Feature||Android||Chrome for Android||Edge||Firefox Mobile (Gecko)||IE Mobile||Opera Mobile||iOS WebKit |
|Basic support||?||?||?||4.0 (4.0)||?||(Yes)||3.1|
 Safari doesn't do validation, but instead offers a custom "email" keyboard, which is designed to make entering email addresses easier. Also, note that Safari mobile on iOS devices automatically applies a default style of
opacity: 0.4 to disabled textual
<input> elements, including those of type
"email". Other major browsers don't currently share this particular default style.
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.