HTML type Attribute

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Controls

Introduction

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.

What You’ll Learn

01

Input types

text, email, etc.

02

Button types

submit vs button.

03

Validation

Browser hints.

04

Checkbox & radio

Choice controls.

05

JavaScript

Change at runtime.

06

Other elements

ol, script, etc.

Purpose of type

The 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.

💡
One name, many meanings

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>.

📝 Syntax

Add type with a value that matches the element you are marking up:

type.html
<input type="email" name="contact" required>
<button type="submit">Send</button>
<ol type="a">...</ol>

Syntax Rules

  • Always write the value in quotes: type="email".
  • On <input>, default is text if omitted.
  • On <button> inside a form, default is submit — set type="button" for non-submit actions.
  • Invalid values fall back to the element’s default type.
  • JavaScript: inputElement.type = "date" updates the live control.
  • Pair input types with name, id, and label for accessibility.

💎 Values

The type attribute accepts different values depending on the element. Here are the most common groups:

On <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.

On <button>

  • submit (default in forms) — Sends the form.
  • button — No default submit; use with JavaScript.
  • reset — Clears the form.

On <ol>

  • 1 — Decimal numbers (default).
  • a, A — Lowercase / uppercase letters.
  • i, I — Lowercase / uppercase Roman numerals.

On <script>

  • text/javascript (default) — Classic script.
  • module — ES module (import / export).
input-types.html
<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">

⚡ Quick Reference

ElementCommon type valuesDefault
<input>text, password, email, number, checkbox, radio, file, datetext
<button>submit, button, resetsubmit (in form)
<ol>1, a, A, i, I1
<script>module, text/javascriptJavaScript
Validationemail, url, number, requiredClient hint only
JavaScriptel.type = "date"Runtime switch

Applicable Elements

ElementSupported?Typical use
<input>YesForm controls — primary use of type
<button>YesSubmit, reset, or generic button behavior
<ol>YesOrdered list numbering style
<script>YesClassic vs module JavaScript
<embed>, <object>, <source>YesMIME / plugin hints for media
<link>, <style>YesStylesheet MIME type (rarely needed today)

Input types vs button type

ControlExampleBehavior
<input type="submit">value="Go"Submits form; label from value
<button type="submit">HTML inside buttonSubmits form; richer content (icons, spans)
<button type="button">onclick handlerDoes not submit the form
<input type="checkbox">Multiple selectionsSame name, different values
<input type="radio">One of manySame name; only one checked
<input type="text"> vs emailValidationemail adds format check and mobile keyboard hint

Examples Gallery

Build a login-style form, switch input type with JavaScript, and compare checkbox, radio, and button types.

👀 Live Preview

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

Example — form with input types

A simple form using text, password, email, and submit:

type.html
<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>
Try It Yourself

How It Works

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.

Dynamic Values with JavaScript

Change the input type at runtime when your UI needs to adapt:

dynamic-type.html
<input id="dynamicInput" placeholder="Select a date">

<script>
  document.getElementById("dynamicInput").type = "date";
</script>

How It Works

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.

Example — checkbox, radio, and button types

Choice controls and explicit button behavior inside one form:

controls.html
<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>

How It Works

Checkboxes allow multiple answers; radios enforce one selection per group. Use button type="button" for actions that must not submit the form accidentally.

♿ Accessibility

  • Always use <label> — Connect labels with for and id so screen readers announce the control purpose.
  • Pick semantic typesemail, tel, and url expose the right role and mobile keyboards.
  • Do not rely on type alone for securitypassword hides input visually; validate and hash on the server.
  • Group radios and checkboxes — Use <fieldset> and <legend> for related options.
  • Explicit button types — Set type="button" on non-submit buttons to prevent accidental form submission.

🧠 How type Works

1

Author sets type

On input, button, etc.

HTML
2

Browser renders control

UI + validation rules.

Render
3

User interacts

Type, click, pick file.

Input
=

Correct data shape

Better forms.

Browser Support

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.

Excellent · Modern input types

Universal core, rich types in modern browsers

Always validate on the server; treat client-side type validation as a convenience, not security.

98% Modern browsers
Google Chrome Full support
Supported
Mozilla Firefox Full support
Supported
Apple Safari Full support
Supported
Microsoft Edge Full support
Supported
type on <input> Excellent

Bottom line: Use semantic input types freely; provide fallbacks or server validation for critical fields.

💡 Best Practices

✅ Do

  • Use the most specific input type (email, not plain text)
  • Set button type="button" for JS-only actions
  • Combine types with required, pattern, min, max
  • Label every control clearly
  • Validate again on the server

❌ Don’t

  • Assume type="email" blocks invalid submissions alone
  • Leave <button> without an explicit type in complex forms
  • Use type="hidden" for sensitive authorization data
  • Rely on password masking as encryption
  • Mix radio buttons with different name values in one group
  • Understand the purpose of each value and use them to enhance UX and accurate data entry.
  • When designing forms, choose appropriate input types for validation and accessibility.
  • Remember that type is not limited to forms — it also applies to lists, scripts, and media elements where specifying content kind is relevant.

🎉 Conclusion

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.

Key Takeaways

Knowledge Unlocked

4 truths every developer should know about type

Bookmark these before your next type implementation.

4
Core concepts
📝 02

Allowed values depend on

Allowed values depend on the element; do not copy values blindly across elements.

Syntax
⚙️ 03

Default input type is

Default input type is text; default button in a form is submit.

Usage
🔒 04

JavaScript can change input.type

JavaScript can change input.type at runtime (e.g. switch to date).

Dynamic

❓ Frequently Asked Questions

It tells the browser what kind of element or data to expect. On <input> it defines the control and validation behavior. On other elements it has element-specific meanings (button submit behavior, list markers, script module mode).
If you omit type on an <input>, the browser treats it as text. Always set type explicitly for clarity.
Yes. Assign a new string to inputElement.type. Some changes may clear the current value or affect focus; test your specific switch.
Both work. Use <button type="submit"> when you need HTML inside the label (icons, multiple words). Use <input type="submit"> for a simple text label via value.
No. Browser validation from types like email and number runs on the client only. Always re-validate on the server before trusting submitted data.

Practice input types

Build a form with text, password, and email, then try the dynamic date picker example.

Try the form example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful