w3resource

HTML type attribute

type

The purpose of the HTML type attribute is to specify the content type of the associated element when used with a, link, object, param, script, style elements. When used with the input element, the attribute specifies the type of the date it can accept. Whereas when used with button element, the attribute can be used to define the type of work the associated button can perform (for whether it is to be used to submit a form, reset a form etc.).

Supported elements

HTML type attribute supports a, button, input, link, object, param, script, style elements.

Syntax

<ElementName type="value" >.....</ElementName>

Where ElementName is any supported element.

Type of value

ContentType for a, link, object, param, script, style.

InputType for input element.

LIStyle for li element, OLStyle for ol element and ULStyle for ul element.

Different values (button | submit | reset) for button element.

Default value

There is no default value of HTML type attribute.

Supported doctypes

HTML 4.01 strict, HTML 4.01 transitional, HTML 4.01 frameset.

Example of HTML type attribute with a element

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML type attribute with a element</title>
</head>
<body>
<p><a href="../../images/w3logo5.gif" type="image/gif">w3resource tutorials</a></p>
</body>
</html>

Result

html type attribute with a element

View this example in a separate browser window

Example of HTML type attribute with a element

Example of HTML type attribute with button, input, link elements

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML type attribute with button, input, link elements</title>
<link rel='stylesheet' href='test.css' type='text/css' /> 
</head>
<body>
<form name="user_info" action="action_post.php" method="post"> 
Name : <input type="text" name="name" /><br/>
email  : <input type="text" name="email"/><br/>
<button type="submit" name="submit">Submit</button>
</form>
</body>
</html>

Result

html type attribute with button input link elements

View this example in a separate browser window

Example of HTML type attribute with button, input and link elements

Example of HTML type attribute with script and style elements

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of HTML type attribute with script and style elements</title>
<script type="text/javascript" src="../../html/attributes/w3r.js"> </script>
<style type="text/css">
p {background-color: lightyellow; color: maroon;} 
</style>
</head>
<body onload="w3r()" >
<p>This is an example of type attribute with script and style elements</p> 
</body>
</html>

Result

html type attribute with script and style elements

View this example in a separate browser window

Example of HTML type attribute with script, style elements

Previous: HTML title attribute
Next: HTML usemap attribute