HTML Script tag: type or language (or omit both)?
Which should be used and why?
Or, the third alternative: omitting either of these, such as the example code in jQuery’s API reference:
language attribute has been deprecated for a long time, and should not be used.
type, so they standardized it to be the default value. Hence, you don’t need
For pages in XHTML 1.0 or HTML 4.01 omitting
type is considered invalid. Try validating the following:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script src="http://example.com/test.js"></script> </head> <body/> </html>
You will be informed of the following error:
Line 4, Column 41: required attribute “type” not specified
So if you’re a fan of standards, use it. It should have no practical effect, but, when in doubt, may as well go by the spec.
HTML5 faces the fact that there is only one scripting language on the web, and allows
The latter works in any browser that supports scripting (NN2+).
The type attribute is used to define the MIME type within the HTML document. Depending on what DOCTYPE you use, the type value is required in order to validate the HTML document.