Script character
Attribute
Example
Retrieve the character set used in an external script file:
x Output result:
Definition and Usage
The charset attribute sets or returns the value of the charset attribute of a script.
The charset attribute specifies the character encoding used in an external script file.
The charset attribute is used when the character encoding of the external script file differs from the encoding of the HTML document.
Note: The charset attribute is only applicable to external scripts (only when the src attribute is used).
Browser Support
All major browsers support the charset attribute.
Syntax
Return the charset attribute:
Set the charset attribute:
Attribute Values
Value | Description |
---|---|
charset | Specifies the character encoding of the external script file. Some common values: "ISO-8859-1" - Standard encoding for the Latin alphabet<br> "UTF-8" - Unicode character encoding. Compatible with ASCII. See our Character Sets Reference for a complete list of character sets. |
Technical Details
| Return Value: | A string, representing the URL of the external script file. Returns the full URL, including the protocol (e.g., http://). | | --- | --- |
Related Articles
HTML Reference: HTML <script> charset Attribute