About This HTML Issue
The <script> element’s type attribute specifies the MIME type of the script. In earlier HTML versions (HTML 4 and XHTML), the type attribute was required and authors had to explicitly declare type="text/javascript". However, the HTML5 specification changed this — JavaScript is now the default scripting language, so when the type attribute is omitted, browsers automatically treat the script as JavaScript.
Because of this default behavior, including type="text/javascript" (or variations like type="application/javascript") is unnecessary. The W3C HTML Validator raises a warning to encourage cleaner, more concise markup. While this isn’t an error that will break your page, removing the redundant attribute keeps your HTML lean and aligned with modern standards.
There are legitimate uses for the type attribute on <script> elements, such as type="module" for ES modules or type="application/ld+json" for structured data. These values change the behavior of the <script> element and should absolutely be kept. The validator only flags the attribute when its value is a JavaScript MIME type, since that’s already the default.
Examples
Incorrect — unnecessary type attribute
<script type="text/javascript" src="app.js"></script>
<script type="text/javascript">
console.log("Hello, world!");
</script>
Correct — type attribute removed
<script src="app.js"></script>
<script>
console.log("Hello, world!");
</script>
Correct — type attribute used for non-default purposes
The type attribute is still necessary and valid when you’re using it for something other than plain JavaScript:
<!-- ES module -->
<script type="module" src="app.mjs"></script>
<!-- JSON-LD structured data -->
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"name": "Example Inc."
}
</script>
<!-- Import map -->
<script type="importmap">
{
"imports": {
"utils": "./utils.js"
}
}
</script>
Quick fix checklist
-
Search your HTML files for
type="text/javascript"andtype="application/javascript". -
Remove the
typeattribute from those<script>tags entirely. -
Leave the
typeattribute on any<script>tags that usetype="module",type="importmap",type="application/ld+json", or other non-JavaScript MIME types.
Find issues like this automatically
Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.