The HTML type attribute
The HTML type attribute specifies the MIME type (media type) of a resource or the script type. It is used on the <script>, <style>, <link>, <source>, <embed>, <object> and <a> elements.
Overview
The type attribute states the MIME type (media type) of a resource, telling the browser what kind of content to expect. On a <source> it lets the browser skip formats it cannot play without downloading them; on a <link> or <a> it hints the linked resource's type; on a <script> it distinguishes classic scripts from modules.
Be aware that several elements have their own, different type attribute documented separately: on an <input> it sets the control type (text, email, checkbox…), on a <button> it sets the behavior (submit, button, reset), and on an <ol> it sets the marker style.
For scripts, the important modern value is type="module", which marks an ES module. The old type="text/css" on <style> and type="text/javascript" on <script> are now unnecessary defaults you can drop.
Syntax
<script type="module" src="app.js"></script>
Values
| Value |
|---|
A MIME type such as text/css or image/webp — or module on a <script>. |
Best practices
Frequently asked questions
What does the type attribute specify?
Do I need type="text/javascript" on a script?
type="module" only when you want an ES module.