👀 Live Preview
How different input types look in the browser (email shows validation on invalid input):

The type attribute is a fundamental HTML feature used to define what kind of content or behavior an element represents. It is most famous on <input>, where it turns a generic field into a text box, password field, email validator, checkbox, date picker, file uploader, and more.
The same attribute name appears on other elements too — such as <button>, <ol>, and <script> — but with different allowed values for each element. Understanding type is essential for building effective, accessible web forms.
text, email, etc.
submit vs button.
Browser hints.
Choice controls.
Change at runtime.
ol, script, etc.
typeThe primary purpose of the type attribute is to tell the browser how to render an element and how to handle user interaction or data. For form controls, it drives the UI (keyboard on mobile, date picker, masked password), built-in validation, and what gets sent when the form is submitted.
Choosing the correct input type improves user experience, reduces errors, and helps assistive technologies describe controls accurately.
type is not a single global enum. Always check which element you are using — type="submit" on <button> means something different from type="1" on <ol>.
Add type with a value that matches the element you are marking up:
<input type="email" name="contact" required>
<button type="submit">Send</button>
<ol type="a">...</ol>type="email".<input>, default is text if omitted.<button> inside a form, default is submit — set type="button" for non-submit actions.inputElement.type = "date" updates the live control.name, id, and label for accessibility.The type attribute accepts different values depending on the element. Here are the most common groups:
<input> (most common)text — Single-line text (default).password — Masked secret entry.email — Email address with format validation.number — Numeric input; use with min, max, step.checkbox — On/off toggle; multiple allowed per name.radio — One choice from a group sharing the same name.submit — Submits the form.button — Generic push button (no submit).reset — Resets form fields to defaults.file — File picker; often paired with accept.hidden — Not shown; sends data with the form.date, time, color, range — Specialized pickers.<button>submit (default in forms) — Sends the form.button — No default submit; use with JavaScript.reset — Clears the form.<ol>1 — Decimal numbers (default).a, A — Lowercase / uppercase letters.i, I — Lowercase / uppercase Roman numerals.<script>text/javascript (default) — Classic script.module — ES module (import / export).<input type="text" name="username">
<input type="password" name="password">
<input type="email" name="email">
<input type="checkbox" name="agree" value="yes">
<input type="submit" value="Submit">| Element | Common type values | Default |
|---|---|---|
<input> | text, password, email, number, checkbox, radio, file, date | text |
<button> | submit, button, reset | submit (in form) |
<ol> | 1, a, A, i, I | 1 |
<script> | module, text/javascript | JavaScript |
| Validation | email, url, number, required | Client hint only |
| JavaScript | el.type = "date" | Runtime switch |
| Element | Supported? | Typical use |
|---|---|---|
<input> | Yes | Form controls — primary use of type |
<button> | Yes | Submit, reset, or generic button behavior |
<ol> | Yes | Ordered list numbering style |
<script> | Yes | Classic vs module JavaScript |
<embed>, <object>, <source> | Yes | MIME / plugin hints for media |
<link>, <style> | Yes | Stylesheet MIME type (rarely needed today) |
type| Control | Example | Behavior |
|---|---|---|
<input type="submit"> | value="Go" | Submits form; label from value |
<button type="submit"> | HTML inside button | Submits form; richer content (icons, spans) |
<button type="button"> | onclick handler | Does not submit the form |
<input type="checkbox"> | Multiple selections | Same name, different values |
<input type="radio"> | One of many | Same name; only one checked |
<input type="text"> vs email | Validation | email adds format check and mobile keyboard hint |
Build a login-style form, switch input type with JavaScript, and compare checkbox, radio, and button types.
How different input types look in the browser (email shows validation on invalid input):
A simple form using text, password, email, and submit:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<input type="submit" value="Submit">
</form>Each type value tells the browser which control to render. Password masks characters; email adds basic format validation; submit sends the form data to the server.
Change the input type at runtime when your UI needs to adapt:
<input id="dynamicInput" placeholder="Select a date">
<script>
document.getElementById("dynamicInput").type = "date";
</script>The script sets type to date, so the browser replaces the plain text field with a date picker. Useful when toggling between text and specialized inputs based on user choices.
Choice controls and explicit button behavior inside one form:
<input type="checkbox" name="newsletter" value="yes"> Subscribe
<input type="radio" name="plan" value="free" checked> Free
<input type="radio" name="plan" value="pro"> Pro
<button type="button">Preview</button>
<button type="submit">Save</button>Checkboxes allow multiple answers; radios enforce one selection per group. Use button type="button" for actions that must not submit the form accidentally.
<label> — Connect labels with for and id so screen readers announce the control purpose.email, tel, and url expose the right role and mobile keyboards.password hides input visually; validate and hash on the server.<fieldset> and <legend> for related options.type="button" on non-submit buttons to prevent accidental form submission.On input, button, etc.
UI + validation rules.
Type, click, pick file.
Better forms.
Basic input types (text, password, checkbox, radio, submit) work everywhere. Newer types (email, date, color, range) are supported in all modern browsers; very old browsers may treat unknown types as text.
Always validate on the server; treat client-side type validation as a convenience, not security.
<input> ExcellentBottom line: Use semantic input types freely; provide fallbacks or server validation for critical fields.
email, not plain text)button type="button" for JS-only actionsrequired, pattern, min, maxtype="email" blocks invalid submissions alone<button> without an explicit type in complex formstype="hidden" for sensitive authorization dataname values in one grouptype is not limited to forms — it also applies to lists, scripts, and media elements where specifying content kind is relevant.The type attribute plays a crucial role in defining the nature of data and behavior within HTML elements, especially in web forms. By choosing the right type for each control, you create more user-friendly, accessible applications with fewer input errors.
Start with explicit input types on every field, use button types deliberately, and explore dynamic changes with JavaScript when your interface needs to adapt.
typeBookmark these before your next type implementation.
type on <input> is the most common use — it controls UI, validation, and submission.
Allowed values depend on the element; do not copy values blindly across elements.
SyntaxDefault input type is text; default button in a form is submit.
JavaScript can change input.type at runtime (e.g. switch to date).
<input> it defines the control and validation behavior. On other elements it has element-specific meanings (button submit behavior, list markers, script module mode).type on an <input>, the browser treats it as text. Always set type explicitly for clarity.inputElement.type. Some changes may clear the current value or affect focus; test your specific switch.<button type="submit"> when you need HTML inside the label (icons, multiple words). Use <input type="submit"> for a simple text label via value.email and number runs on the client only. Always re-validate on the server before trusting submitted data.Build a form with text, password, and email, then try the dynamic date picker example.
5 people found this page helpful