CKTIS / HTML
type — element-dependent meaning in HTML
The type attribute is not a global attribute. Depending on the element, it selects a control kind, button behavior, list numbering, or script processing mode, or describes a resource's MIME type. Valid values and defaults depend on the element.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
type="value"type uses the syntax type="value", but has no single meaning throughout HTML. It is not a global attribute: interpret its value according to the element carrying it. A keyword such as number is not the same thing as a MIME type such as image/webp.
On input, it selects the control kind, such as text, number, email, or checkbox, and affects value handling, validation, and available APIs. A missing or invalid value means the Text state. On button, submit, reset, and button determine its action. A missing or invalid value selects the Auto state: the button is a submit button if neither command nor commandfor is present and its parent is not select. The submit state also makes it a submit button. Explicitly use type="button" for buttons handled only by scripts.
On ol, 1, a, A, i, and I select decimal numbering, lowercase or uppercase letters, and lowercase or uppercase Roman numerals respectively; the default is 1. On script, an omitted or empty type means classic JavaScript. module selects a JavaScript module, importmap an import map, and speculationrules speculative loading rules. A type value also selects a classic script if the entire value is an ASCII case-insensitive match for a recognized JavaScript MIME type essence (the MIME type without parameters). For example, text/javascript matches, but text/javascript; charset=utf-8 does not, so the latter does not execute the script. A valid non-JavaScript MIME type such as application/json denotes a data block rather than executable JavaScript.
On source, embed, and object, the value is a valid MIME type for the resource. source helps the browser select a supported source. On embed, the declaration must match the resource's explicit Content-Type metadata when src is also supplied. On object, an unsupported declared type can cause fallback content to be used without fetching the resource.
On a and area, the MIME type is purely advisory and does not determine the fetched resource's type. On link, it is also a hint; for external resources it can prevent fetching an unsupported format. Do not treat type as a universal way to override the HTTP Content-Type header.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>type example</title>
<form>
<label>Quantity <input id="quantity" type="number" value="2" min="1"></label>
<button id="check" type="button">Check</button>
</form>
<pre id="result"></pre>
<script>
const quantity = document.getElementById('quantity');
const check = document.getElementById('check');
const result = document.getElementById('result');
check.addEventListener('click', () => {
result.textContent = quantity.type + ': ' + quantity.valueAsNumber;
});
</script>
</html>Result
number: 2
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.