Open In App

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

Last Updated : 18 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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:


Previous Article
Next Article

Similar Reads

How to specify the type of the media resource in HTML5 ?
Here, we will see how to set the media type of the media resource using HTML. To select the media type of media resource we use the &lt;source&gt; tag. This tag is used to attach multimedia files like audio, video, and pictures to a web page or website. The &lt;audio&gt;, &lt;video&gt;, and &lt;picture&gt; elements contain the &lt;source&gt; elemen
1 min read
How to specify media type of data specified in data attribute in HTML5 ?
The following approach covers how to specify the URL of the resource to be used by the object in HTML5. This can be used in pages where content from an external source is required. Approach: We will use the data attribute of the &lt;object&gt; element to specify the URL of the resource that to be used for the object. The specified URL can be relati
1 min read
How to specify media type of the target URL in HTML5 ?
You can easily specify the media type of the target URL in HTML5 using the media attribute of HTML. This attribute is used to specify that the target URL is designed for special devices (like iPhone, Android, etc), speech or print media, projectors, tv, and so on. Syntax: &lt;a href="" media="screen" target=”_blank”&gt; Click here&lt;/a&gt; Note: T
1 min read
How to specify the URL of the media file in HTML5 ?
Here we will see how to set the URL of a media file using HTML. To set the URL of media file we use &lt;source&gt; tag. This tag is used to attach multimedia files like audio, video and pictures. The &lt;audio&gt;, &lt;video&gt; and &lt;picture&gt; elements contain the &lt;source&gt; element. Syntax: &lt;source src="" type=""&gt; // Statements &lt;
1 min read
How to specify the character encoding used in an external script file in HTML5 ?
To specify the character encoding used in an external script file in HTML5 we use &lt;script&gt; charset attribute. The charset attribute specifies the character encoding for the HTML document when used by the &lt;meta&gt; element. The charset attribute specifies the character encoding used in an external script file when used by the &lt;script&gt;
1 min read
How to specify the type of button using HTML5 ?
In this article, we will see how to set the button type using HTML. The &lt;button&gt; tag in HTML is used to create a clickable button within form on your webpage. The button type attribute specifies the type of button (You Should Always Declare the type of button). The &lt;button&gt; tag defines a clickable button and used to submit forms or anyw
1 min read
How to specify the type of button using HTML5 ?
To specify the button type in HTML5, we can use the HTML | &lt;button&gt; type Attribute. This attribute is used to specify the type of button. It specifies the type attribute of the &lt;button&gt; element. The default types of &lt;button&gt; elements can vary from browser to browser. Syntax: &lt;button type="button|submit|reset"&gt; Example: C/C++
1 min read
How to specify the type of files that server accepts in HTML5 ?
In this article, we will learn how to specify the types of files that the server accepts in HTML5. The &lt;input&gt; accept attribute is used to specify the type of file that the server accepts. This attribute can be used with &lt;input type="file"&gt; element only. This attribute is not used for validation tools because file uploads should be vali
2 min read
How to define the type of media resource in HTML5 ?
We can define or specify the type of media file (audio, video, etc) in HTML by the &lt;source&gt; tag. It defines the multimedia resources and gives the browser multiple and alternative types of that media file from which the browser can choose according to its compatibility with that media type. Note: Browser chooses the first media type that it s
2 min read
How to define media type of style tag in HTML5 ?
In this article, we learn how to define the media type of the style tag in HTML5. In HTML5, the media type of a style tag can be defined using the "media" attribute. By specifying the media type, such as "screen" for displaying on a screen or "print" for printing, the style rules within the style tag will be applied accordingly to the specific medi
2 min read