English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: charset Attribute of <script>

The charset attribute specifies the character encoding used in the external script file. When the character encoding of the external script file is different from the character encoding of the HTML document, use the charset attribute.

 HTML <script> tag

Online Example

With UTF-8External JavaScript for character set:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>HTML: Use of charset Attribute in script>-Basic Tutorial Website (www.3codebox.com)</<title> 
</<head>
<body>
<script charset="UTF-8"src="demo_script_charset.js"></script>
Greek characters are displayed correctly because they are "UTF-8" is part of the character set.</p>
Attempt to change the character set to "ISO-8859-1(Default)-1252"or"UTF"-16”。</p>
</body>
</html>
Test it out ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the charset attribute.

Definition and Usage

The charset attribute specifies the character encoding used in the external script file.

Use the charset attribute when the character encoding of the external script file is different from the character encoding of the HTML document.

Tips and Notes

Note:The charset attribute applies only to external scripts (only when the src attribute is used).

HTML 4.01 with HTML5differences

None.

Syntax

<script charset="charset">

Attribute Value

ValueDescription
charsetSpecifies the character encoding of the external script file.

Some commonly used values:

  • "ISO-8859-1" - standard encoding of the Latin alphabet

  • "UTF-8" - Unicode character encoding. Compatible with ASCII

Please refer to our Character Set Reference Manual,for a complete list of character sets.

 HTML <script> tag