Skip to: content, navigation

charset (HTML attribute)

Spec
Depr. Version
No HTML 4
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+
Full Full Full Full

Syntax

charset="character encoding scheme"

Description

The charset attribute defines the character encoding used in a linked script file (which is referred to by the src attribute). You’d use this attribute when the character encoding employed by the external JavaScript file differs from that of the main document. For example, the external script file has the following script:

If the document that links to this eternal file is declared as using "ISO 8859-1" encoding, the alert text would be unreadable nonsense. Adding charset="utf-8" to the script start tag makes it display correctly.

Example

This example shows a script file that’s using a slightly different character encoding from the default "ISO-8859-1":

<script type="text/javascript" src="/scripts/common.js"
  charset="ISO-8859-15"></script>

Value

The charset attribute takes as its value a space and/or a comma-delimited list of character sets, as set out in RFC 2045 (a fun bit of bedtime reading).

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Full Full Full Full Full Full Full Full Full Full Full

Every browser listed supports this attribute.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

Search