Type attribute in the JavaScript tag

 What is the need of type attribute in the JavaScript tag?

Last updated:7/19/2021 5:08:46 AM

1 Answers

Ethan Karla
Ethan Karla

Since HTML 4.x, the type attribute in a script tag specifies the scripting language of the element's content and overrides the default scripting language. The scripting language is specified as a content type (for example, 'text/javascript'). Authors must provide a value for this attribute. There is no default value for this attribute.

But after HTML5 was released, the type attribute in script tags became optional. The type attribute gives the language of the script or format of the data. If the attribute exists, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is 'text/javascript'.