- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - type Attribute
The type is an HTML attribute that specifies the type of element. This is used to specify the type of button for the <button> tag, and it is also used in the <input> tag to specify the type of input to display.
The type attribute determines the internet media type (often referred to as MIME type) for the <embed>, <link>, <object>, <script>, <source>, and <style> elements.
Following are the elements where the type attribute can be used−
S.No | Elements |
---|---|
1 | <a> |
2 | <button> |
3 | <embed> |
4 | <input> |
5 | <link> |
6 | <menu> |
7 | <object> |
8 | <script> |
9 | <source> |
10 | <style> |
Syntax
Following is the syntax of the type attribute −
<element type="value">
Example
In the following example, we are going to use type attribute with the input element.
<!DOCTYPE html> <html> <body> <h1>The button type attribute</h1> <form action="" method="post"> <label for="fname">First name:</label> <input type="text" id="fname" name="fname"> <br> <br> <label for="lname">Last name:</label> <input type="text" id="lname" name="lname"> <br> <br> <button type="submit" value="Submit">Submit</button> <button type="reset" value="Reset">Reset</button> </form> </body> </html>
On running the above code, the output window will pop up displaying the input field along with a submit and reset button on the webpage.
Example
Considering the another scenario, where we are going to use the type attribute with the embed element.
<!DOCTYPE html> <html> <body> <h1>The embed type attribute</h1> <embed type="image/jpg" src="https://www.tutorialspoint.com/images/logo.png?v2" /> </body> </html>
When we run the above code, it will generate an output consisting of the image displayed on the webpage.
Example
Let's look into the following example, where we are going to use the type attribute with the link element.
style.css
body{ background-color: purple; } h2{ color: green; } span{ color: black; }
type.html
<!DOCTYPE html> <html> <body> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <h2> tutorials <span>point</span> </h2> <h3> link element with type attribute </h3> <p> this is external CSS </p> </body> </html>
On running the above code, the output window will pop up displaying the text applied with CSS on the webpage.
To Continue Learning Please Login
Login with Google