Require valid type for <script> element

Rule ID:
script-type
Category:
HTML Syntax and concepts
Standards:
  • HTML5

The HTML5 standard encourages omitting the type attribute when the script is a JavaScript resource and only use it to specify module or other non-javascript MIME types.

Rule details

Examples of incorrect code for this rule:

<script type=""></script>
<script type="text/javascript"></script>
<script type="application/javascript"></script>
error: "type" attribute is unnecessary for javascript resources (script-type) at inline:1:9:
> 1 | <script type=""></script>
    |         ^^^^
  2 | <script type="text/javascript"></script>
  3 | <script type="application/javascript"></script>


error: "type" attribute is unnecessary for javascript resources (script-type) at inline:2:9:
  1 | <script type=""></script>
> 2 | <script type="text/javascript"></script>
    |         ^^^^
  3 | <script type="application/javascript"></script>


error: "type" attribute is unnecessary for javascript resources (script-type) at inline:3:9:
  1 | <script type=""></script>
  2 | <script type="text/javascript"></script>
> 3 | <script type="application/javascript"></script>
    |         ^^^^


3 errors found.

Examples of correct code for this rule:

<script></script>
<script type="module"></script>
<script type="text/plain"></script>
<script type="text/x-custom"></script>