Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "lang" and "type" attributes in a script tag?

Tags:

html

scripting

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.

like image 529
Dustman Avatar asked Sep 21 '08 23:09

Dustman


People also ask

What is type attribute in script tag?

The type attribute specifies the type of the script. The type attribute identifies the content between the <script> and </script> tags.

What is a lang attribute?

The HTML lang attribute is used to identify the language of text content on the web. This information helps search engines return language specific results, and it is also used by screen readers that switch language profiles to provide the correct accent and pronunciation.

What are the two attributes of script tag?

Attributes: Many attribute associated with script tag. async: It is used to specify the script is executed asynchronously. charset: It is used to specify the character encoding used in an external script file.

What does lang mean in JavaScript?

The lang (or sometimes the xml:lang ) attribute specifies the natural language of the content of a web page. An attribute on the html tag sets the language for all the text on the page.


2 Answers

The OP specifically said "lang" not "language". The much older "language" tag would have been Javascript or VBScript.

But the current and seemingly valid "lang" tag is actually which written language like English, Spanish, Japanese. Microsoft's Visual Studio provides a dropdown list for the values for "lang" and they are all like en-us, fr, ja, etc.. for English US, French, Japanese, etc...

I'm thinking there could be valid reasons for using this tag if you have a complex multilingual setup - maybe there's a content mgmt system that could support this and then deliver the proper javascript file - like jQuery control resources?

like image 56
David Storfer Avatar answered Sep 19 '22 03:09

David Storfer


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.

like image 25
Eric Lathrop Avatar answered Sep 23 '22 03:09

Eric Lathrop