Skip to content
Related Articles

Related Articles

Improve Article

How to specify the media type of the script in HTML5 ?

  • Last Updated : 18 May, 2021

The HTML <script> type attribute specifies the type of script that is being represented. The type attribute identifies the content that appears between the <script> and </script> tags. It specifies the script’s MIME type and identifies the Tag’s content. It has a single value, media type, that specifies the MIME type of the script. It has a default value of “text/javascript.”

Note: JavaScript no longer requires the type attribute in HTML5.

Syntax :

<script type="script_media_type">

This attribute’s value will fall into one of the following categories:

  • <script type=”text/javascript “>
  • <script type=”application/javascript”>
  • <script type=”application/ecmascript”>
  • <script type=”text/ecmascript”>

Example :



HTML




<!DOCTYPE html>
<html>
  
<script type="text/javascript">
    let typeValue = document.querySelector('script[type]');
    let id = typeValue.getAttribute('type');
</script>
  
<body>
  
    <h2>
        Specifying the media type of the script in HTML5
    </h2>
    <p>Media Type of Script:
        <strong id="scriptType"></strong>
    </p>
  
    <script>
        document.getElementById("scriptType").innerHTML = id;
    </script>
  
</body>
  
</html>

Output:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :