Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

HTML <script> type Attribute

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".

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

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.


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>
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest self-service freelancing marketplace for people like you.

Guides