Coder Perfect

Type or language (or both) for the HTML Script tag?


<script type="text/javascript">
    /* ... */


<script language="Javascript">
    /* ... */

What should be used and why should it be used?

Alternatively, you might skip either of them, as seen in the example code in the jQuery API reference:

<script src=""></script>

Asked by Ricket

Solution #1

For a long time, the language attribute has been deprecated, and it should no longer be utilized.

When the W3C began working on HTML5, they realized that “text/javascript” was the default script type in all browsers, so they made it the default setting. As a result, you don’t need to type.

Omitting type in XHTML 1.0 or HTML 4.01 is considered incorrect. Attempt to validate the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en" lang="en">
<script src=""></script>

The following error will be displayed to you:

So, if you like standards, go ahead and use it. It should have no practical effect, but if in question, go with the specification.

Answered by Matchu

Solution #2

HTML4/XHTML1 requires

<script type="...">...</script>

HTML5 addresses the fact that there is only one scripting language on the internet and allows users to create their own.


The latter is compatible with any browser (NN2+) that supports scripting.

Answered by Ms2ger

Solution #3

Within an HTML document, the type attribute is used to specify the MIME type. The type value may be necessary to validate the HTML document, depending on the DOCTYPE you select.

The language element informs the browser about the scripting language you’re using (Javascript vs. VBScript), but it’s not required and has been deprecated, IIRC.

Answered by JasCav

Post is based on