HTML Tutorial / Choose Input Types for Email, Numbers, Dates, and Choices
The type of an input tells the browser what kind of value or selection the field represents. Email, numeric quantities, dates, checkboxes, and radio buttons have different behaviors. Choose the type according to the data and decision users must make, not merely its visual appearance.
Match the type to the value
<form method="get">
<p><label for="email">Email</label>
<input id="email" name="email" type="email"></p>
<p><label for="quantity">Quantity</label>
<input id="quantity" name="quantity" type="number" min="1"></p>
<p><label for="visit-date">Visit date</label>
<input id="visit-date" name="date" type="date"></p>
<button type="submit">Check</button>
</form>
Save the example in an HTML file and try each field. email can provide basic address-format validation and a suitable input interface on some devices. number can enforce a numerical minimum; the visible control for date depends on the browser and operating system. The server must still check that a submitted date is valid for the application's purpose.
A quantity is a number you can calculate with, but a postal code may have leading zeros and a telephone number may include a country code or punctuation. Use text or tel for such values rather than number. Ask whether the value is a numerical quantity, not simply whether it contains digits.
Checkboxes or radio buttons?
Choose a checkbox for an independent yes/no decision or multiple independent selections. Choose radio buttons with the same name when exactly one option from a group may be selected. Compare group naming with the fieldset and legend example in Explain Forms with fieldset, legend, and autocomplete.
<fieldset>
<legend>Updates</legend>
<label><input type="checkbox" name="news" value="yes"> Receive news</label>
</fieldset>
<fieldset>
<legend>Preferred contact method</legend>
<label><input type="radio" name="contact" value="email"> Email</label>
<label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>
The radio inputs share name="contact", so selecting one clears the other. value is the submitted value, which need not match the visible label. Put these groups inside a form with a submit button to test them: an unchecked news checkbox contributes no entry, while selecting Email sends contact=email. If your application must distinguish an explicit “No” from no response, design that choice and its server handling deliberately.
Compare the interface with submitted values
| type | Purpose | Caution |
|---|---|---|
| An email-format string | Does not verify that a mailbox exists | |
| number | A numerical quantity | Range, step, and whether empty is allowed are separate |
| date | A date | The interface varies by locale; the value uses yyyy-mm-dd |
| checkbox | An independent choice | An unchecked control contributes no entry |
| radio | One choice from a same-name group | A shared fieldset does not replace a shared name |
Save the complete example as visit.html and use the test address name@example.com. Leaving the required radio group unanswered blocks submission, while the optional News choice changes the data list.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Visit input-types practice</title>
</head>
<body>
<h1>Practice a visit request</h1>
<form id="visit-form" method="get">
<p><label for="visit-email">Email</label>
<input id="visit-email" name="email" type="email" required></p>
<p><label for="visit-day">Visit date</label>
<input id="visit-day" name="date" type="date" required></p>
<p><label for="visit-quantity">Quantity</label>
<input id="visit-quantity" name="quantity" type="number" min="1" step="1" value="1"></p>
<fieldset>
<legend>Contact method</legend>
<label><input type="radio" name="contact" value="email" required> Email</label>
<label><input type="radio" name="contact" value="phone"> Phone</label>
</fieldset>
<p><label><input type="checkbox" name="news" value="yes"> News</label></p>
<button type="submit">Inspect entered values</button>
</form>
</body>
</html>
Choose a date and inspect document.getElementById("visit-day").value in the console. Selecting 20 May 2030 produces a value in the form 2030-05-20, regardless of the localized calendar display. Toggle News and compare the entry list with the command below.
Array.from(new FormData(document.getElementById("visit-form")).entries())
Check more than the type
Each field still needs an understandable label and, when its value must be submitted, a name. A field of type="email" can be left empty unless you also require a value; format and requiredness are separate rules. You can add required to a radio group when choosing one answer is truly mandatory. Test what the browser submits and validate important values on the server. The MDN input reference lists supported types and constraints. Type and requiredness, length, and range are separate; test their boundary cases in Form Validation with required, Length, and Range Limits.




