The type attribute on an <script> tag specifies the media type of the script.
A media type indicates the format and nature of the file.
On an <script> tag, the default is "application/javascript".
A type attribute on an <script> element. The attribute specifies the media type (formerly MIME type) of the script.
<p id="target"></p>
<script type="application/javascript">
(() => {
document.getElementById("target").innerHTML = "This text is written by JavaScript.";
})();
</script>
A media type, formerly known as a MIME type, indicates the format and nature of a script.
Browsers don't look at a resource's file extension, but rather what media type it is.
For a script the default type is 'application/javascript'.
A list with common media types is available on this site.
Tip: The IANA organization maintains a full list of official media types.
<script type="media-type">
Value | Description |
---|---|
media-type | The media type of the script. The default is "application/javascript". |
Here is when type support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <script>