Latest web development tutorials

HTML script type property

HTML script tags reference manual HTML <script> tag

Examples

With the specified type attribute script:

<script type="text/javascript">
document.write("Hello World!");
</script>

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the type attribute.


Definition and Usage

type attribute specifies the MIME type of the script.

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

MIME type consists of two parts: media type and subtype. For JavaScript, MIME type is "text / javascript".


Differences between HTML 4.01 and HTML5

In HTML5, type attribute is no longer necessary. The default value is "text / javascript".


grammar

<script type="MIME_type">

Property Value

描述
MIME_type 规定脚本的 MIME 类型。

一些常用的值:
  • text/javascript (默认)
  • text/ecmascript
  • application/ecmascript
  • application/javascript
  • text/vbscript

请参阅 IANA MIME 类型 ,获得标准 MIME 类型的完整列表。



HTML script tags reference manual HTML <script> tag