HTML type Attribute

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The type attribute defines the kind of element behavior or resource. Its allowed values depend on the element: most often <input> (form widgets) and <button> (submit / reset / button), also <script>, <link>, <ol>, and a few others.

On <input>, omitting type (or using an unknown value) falls back to text. Related form attributes: name, value, and required.

Baseline · Widely available.

Not deprecated. Core HTML. Individual input types vary slightly by browser, but common types (text, password, email, checkbox, radio, submit, …) are widely supported.

Not one meaning for every tag.

type on input is not the same as type on script or ol. Always read the values for the element you are using. Do not confuse with the separate legacy typemustmatch attribute.

HTML Syntax

syntax.html
<element type=" value">

Common shapes: <input type="email">, <button type="submit">, <script type="module">, <ol type="A">.

Attribute Values

Values are element-specific. Common beginner set:

Element / valueDescriptionTry it
input → textDefault single-line text fieldTry it
input → password, email, number…Specialized widgets + soft validation / keyboardsTry it
input → checkbox, radioBoolean or exclusive choice controlsTry it
button → submit | reset | buttonForm action; default for <button> is submitTry it
script → module (or omit)ES module vs classic scriptTry it
ol → 1 | a | A | i | IList marker numbering styleTry it

Full <input> type list lives on the input element page (date, file, color, range, and more).

Live Preview

Change type on a single <input> and watch the control change.

Same field, different type — keyboard, masking, and validation change with the widget.

Sample input

type="text"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Common <input> Types

Pick the widget that matches the data you need.

HTML
<form>
  <label>Name
    <input type="text" name="name" required>
  </label>
  <label>Email
    <input type="email" name="email" required>
  </label>
  <label>Password
    <input type="password" name="pass" required>
  </label>
  <label>
    <input type="checkbox" name="agree" value="yes">
    I agree
  </label>
  <button type="submit">Sign up</button>
</form>
Try It Yourself

How It Works

  1. type selects the control — text box, email field, password mask, checkbox.
  2. Browsers may validate lightly — e.g. email format before submit.
  3. Mobile keyboards adapt — email often shows @.
  4. Always validate on the server — client types are a UX aid, not security.

Example 2 — <button type> in a Form

Default for <button> is submit — set button for other actions.

HTML
<form id="demo">
  <label>Note
    <input type="text" name="note" value="Hello">
  </label>
  <button type="submit">Save</button>
  <button type="reset">Reset</button>
  <button type="button" id="ping">Ping (no submit)</button>
</form>
<p id="log"></p>

<script>
  document.getElementById("demo").addEventListener("submit", function (e) {
    e.preventDefault();
    document.getElementById("log").textContent = "submit fired";
  });
  document.getElementById("ping").addEventListener("click", function () {
    document.getElementById("log").textContent = "button click — form not submitted";
  });
</script>
Try It Yourself

How It Works

  1. type="submit" — starts form submission (and submit event).
  2. type="reset" — restores default field values.
  3. type="button" — click only; does not submit.
  4. Omit type at your peril — bare <button> inside a form submits.

Example 3 — Script Module & Ordered List

Same attribute name, different jobs on other elements.

HTML
<!-- Classic script: omit type (defaults to JavaScript) -->
<script>
  console.log("classic");
</script>

<!-- ES module -->
<script type="module">
  console.log("module");
</script>

<ol type="A">
  <li>First</li>
  <li>Second</li>
  <li>Third</li>
</ol>
Try It Yourself

How It Works

  1. Omit type on classic scripts — HTML assumes JavaScript.
  2. type="module" — load as an ES module (deferred, strict, import/export).
  3. ol type — chooses marker style (1, a, A, i, I).
  4. Prefer CSS list-style-type for presentational lists when you can — type on ol is still valid HTML.

Edge Cases & Pitfalls

Most bugs come from assuming one type vocabulary for every element, or forgetting button defaults.

fallback

Unknown input type → text

An invalid value still looks like text. The content attribute may keep your string; the IDL type reports "text".

button

Bare <button> submits

Inside a form, default is submit. Use type="button" for clicks that must not send the form.

security

Types are not server validation

type="email" helps UX. Attackers can still POST anything — validate on the server.

script

Skip obsolete script MIME types

You do not need type="text/javascript" for classic scripts. Use type="module" only for modules.

legacy

typemustmatch is different

typemustmatch was an <object> legacy attribute. Do not mix it up with everyday type.

Browser Support

type is a core HTML attribute whose meaning depends on the element. Common input and button types are Baseline widely available.

✓ Baseline · Widely available

type

Supported everywhere modern browsers render HTML. Some newer input types (date, color, …) have historically uneven UI, but remain usable with graceful fallbacks.

98% Global support (approx.)
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 4+
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer 2+ (basic)
Supported
type Widely supported

Bottom line: Safe to rely on for forms and buttons. Check MDN for niche input types if you need pixel-perfect picker UI on every browser.

Key Takeaways

  • Role: declare what kind of control or resource the element is.
  • Input: defaults to text; pick email, password, checkbox, and so on for better UX.
  • Button: use type="button" when you must not submit the form.
  • Context: same name, different vocabularies per element.

One line: type tells the browser which kind of input, button, script, or list you want — always match the value to the element.

Frequently Asked Questions

It defines the kind of control or resource for the element that owns it. Meaning depends on the element: on input it picks the widget (text, email, checkbox…); on button it sets submit/reset/button; on script or link it is often a MIME type; on ol it sets the list marker style.
If you omit type, or use an unknown value, the input behaves as type="text". The content attribute may still show your invalid string, but the IDL type property returns "text".
Inside a form, a <button> defaults to type="submit". Use type="button" for non-submit actions so clicking does not send the form.
No. type is not one global attribute with one meaning. Always check which element you are on — input, button, script, link, ol, and others each define their own allowed values.
Modern HTML treats classic scripts as JavaScript by default. Prefer omitting type, or use type="module" for ES modules. An obsolete language-style MIME is unnecessary for normal scripts.
No. type itself is standard and widely supported. Some old uses (for example certain presentational values) are obsolete, and typemustmatch on object is a separate legacy attribute — not the same as type.

Next: typemustmatch

Legacy object attribute — separate from everyday type.

typemustmatch tutorial →

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.

8 people found this page helpful