HTML <script> type Attribute

The type attribute on an <script> tag specifies the media type of the script. A media type, formerly known as MIME type, indicates the format and nature of the file. The default is "application/javascript".

Example

#

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> 

Using type

The type attribute specifies the media type of the 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 HTTP Media Types is available on this site.

Tip:   The IANA organization maintains a list of all official media types.


Syntax

<script type="media-type">

Values

#

Value Description
media-type The media type of the script. The default is "application/javascript".

Browser support

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

You may also like

 Back to <script>
Guides