Leaving out type="text/javascript" language="javascript" [duplicate]

I suppose this should be updated now that the landscape has changed quite a bit:

For an HTML5 doctype, it's no longer required. For example: we leave it out of the pages here at Stack Overflow. If you're using an HTML5 doctype then it's completely optional and defaults to text/javascript, so you're absolutely fine leaving it off in every current (or even very old) browser. Realistically, this was also true even in HTML4 though not strictly valid HTML.

For an HTML4 doctype (to be valid), you need it. For a browser to actually function, it's not strictly needed and will behave just fine (this has been true all the way back to Netscape 2) - but it won't be valid HTML. If you have an HTML4 doctype, then keep it around and be valid - cause hey, why not?


Original Answer:

I would use type="text/javascript" to be safe in all current browsers, why leave the ambiguity in there to save 21 characters? language="" however is deprecated, I'd leave it out.

Also, any validator is going to throw an error, though it will likely work inside the browser (unless you're dealing with something very old).


According to the w3c spec, type is required. So... even though most browsers are going to be robust enough to work without type being properly specified, it is good practice to explicitly set it to text/javascript.


The W3C recommendation for HTML5 says that you do not need to include:

type="text/javascript"

The browser assumes that it is text/javascript unless otherwise stated as a different type.

http://dev.w3.org/html5/spec/Overview.html#the-script-block-s-type