Should I include type=\'text/javascript\' in my SCRIPT tags?

The type="text/javascript" attribute in <script> tags is optional in modern HTML5. JavaScript is now the default scripting language for browsers, making this attribute unnecessary in most cases.

HTML5 and Modern Browsers

Since HTML5, browsers automatically assume JavaScript when no type attribute is specified. This simplifies script tags significantly.

Modern Approach (Recommended)

The current best practice is to omit the type attribute entirely:

<html>
   <body>
      <script>
         console.log("Hello World!");
      </script>
   </body>
</html>

Output

Hello World!

Legacy Approach

Older HTML versions required explicit type declaration:

<html>
   <body>
      <script type="text/javascript">
         console.log("Hello World!");
      </script>
   </body>
</html>

Output

Hello World!

When to Use type Attribute

Include type only for non-JavaScript content:

<!-- JSON data -->
<script type="application/json">
   {"name": "John", "age": 30}
</script>

<!-- Template -->
<script type="text/template">
   <div>{{name}}</div>
</script>

Comparison

Approach HTML Version Required? Recommendation
<script> HTML5+ No Use this (modern)
<script type="text/javascript"> HTML 4.01 Yes (legacy) Not needed anymore

Conclusion

Omit type="text/javascript" in modern HTML5 development. Only include type when embedding non-JavaScript content like JSON or templates.

Alshifa Hasnain
Alshifa Hasnain

Converting Code to Clarity

Updated on: 2026-03-15T21:18:03+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements