HTML type Attribute

Description

The HTML type attribute is used to specify the nature or category of the information contained or the control provided by an element within an HTML document. This attribute serves various purposes depending on the context in which it is applied, affecting how the browser will process or display the element to which it is attached. It can be used within <input>, <script>, <style>, <link>, <embed>, and <object> tags, among others, each context giving the attribute a different significance. For instance, in an <input> element, it determines the variety of input control to be displayed, such as a text field, checkbox, or button. In a <script> or <style> element, it specifies the scripting or styling language used. Overall, the type attribute is crucial for ensuring that elements behave or are rendered as intended, contributing to the structure and functionality of web pages.

Syntax

<tagname type="button | checkbox | color | date | datetime-local | email | file |
               hidden | image | number | password | radio | range | reset | search |
               submit | tel | text | time | url | week | 
               1 | a | A | i | I | media-type">

Values

  • buttonDefines a clickable button.
  • checkboxDefines a checkbox.
  • colorUsed for a color picker.
  • dateDefines a date control.
  • datetime-localFor date and time without timezone.
  • emailDefines a field for an e-mail address.
  • fileDefines a file-select field and a "Browse" button for file uploads.
  • hiddenDefines a hidden input field.
  • imageDefines an image as the submit button.
  • numberDefines a field for entering a number.
  • passwordDefines a password field.
  • radioDefines a radio button.
  • rangeFor a range of numbers.
  • resetResets the form to its initial values.
  • searchFor search fields.
  • submitDefines a button for submitting the form data to a form-handler.
  • telFor telephone numbers.
  • textDefines a single-line text input field (default).
  • timeTo select a time (without a date).
  • urlDefines a field for entering a URL.
  • weekTo select a week and year.
  • 1Specifies numbers for ordered list. This is the default. (1, 2, 3, 4).
  • aSpecifies lowercase alphabet for ordered list (a, b, c, d).
  • ASpecifies uppercase alphabet for ordered list (A, B, C, D).
  • iSpecifies lowercase roman numerals for ordered list (i, ii, iii, iv).
  • ISpecifies uppercase roman numerals for ordered list (I, II, III, IV).
  • media-typeMedia type (formerly MIME type) of a linked resource.

Applies To

The type attribute can be used on the following html elements.

Example

<form action="formscript.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label><br>
<input type="password" id="lname" name="lname">
<br><br>
<input type="submit" value="Submit">
</form>

Browser Support

The following table will show you the current browser support for the HTML type Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 30th March 2024