views:

726

answers:

6

For <script> HTML tags, what is the technical difference between "lang=Javascript" and "type=text/javascript"?

I usually use both, because I've always assumed that older browsers need one or the other.

A: 

Type is more general and refers to the mime encoding of the script block. As far as I know you only need one and usually the block will work without either type or lag attributes.

I tend to use type.

Avner
+2  A: 

language is the old attribute, type is the new one. You'd have to use a transitional (not positive on that, but fairly sure) doctype to legally use both attributes.

Jeff Hubbard
A: 

lang is the language of the script, and type is the MIME type of the content of the script tag.

Pablo Fernandez
+3  A: 

<script language=""> can be used for serving VBScript and different versions of Javascript.

Unless you need a specific version of Javascript, don't use the language attribute, your code will still work as normal without it.

Even if you do need a specific Javascript version for some part of the code, try to test if the feature exists instead, with a (typeof window.blah.feature != "undefined") check.

Here is an example of the language attribute's usage: http://bclary.com/2004/08/27/javascript-version-incompatibilities

The language attribute is deprecated because of this loosely defined or uncertain behaviour.

The type attribute is different entirely. It tells the browser what mime type the script is, and should always be specified in a script tag.

Ali
+14  A: 

Per the HTML 4.01 Spec:

type: This attribute specifies the scripting language of the element's contents and overrides the default scripting language. The scripting language is specified as a content type (e.g., "text/javascript"). Authors must supply a value for this attribute. There is no default value for this attribute.

language: Deprecated. This attribute specifies the scripting language of the contents of this element. Its value is an identifier for the language, but since these identifiers are not standard, this attribute has been deprecated in favor of type.

Eric Lathrop
A: 

Basically, neither attribute is necessary. The only reason to use them is validation, and this has become void in HTML5.

Ms2ger