charset (HTML attribute)
| Depr. | Version |
|---|---|
| No | HTML 4 |
| IE8 | FF3.5 | SA4 | OP10 | CH2 |
|---|---|---|---|---|
| None | None | None | None | None |
Syntax
Description
The
charset attribute is intended to identify the
character set used in the document that’s referenced within the
link element.
Example
This example indicates that the referenced document is written in Japanese:
<link href="okinawa.html" rel="parent" charset="euc-jp"/>
Value
The value taken by
charset is a standard character set encoding name (e.g.
"UTF-8") defined by IANA.
Compatibility
| Internet Explorer | Firefox | Safari | Opera | Chrome | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 5.5 | 6.0 | 7.0 | 8.0 | 1.0 | 1.5 | 2.0 | 3.0 | 3.5 | 1.3 | 2.0 | 3.1 | 4.0 | 9.2 | 9.5 | 10.0 | 2.0 |
| None | None | None | None | None | None | None | None | None | None | None | None | None | None | None | None | None |
In testing this
attribute, I was unable to see any difference in behaviour/appearance
regardless of whether the attribute was used or not. However, one reader
has stated that in his tests that omitting this attribute would cause
generated content to appear as gibberish if certain conditions were all
true (namely that the encoding of the document and the linked style sheet
differed and the server was not sending the correct encoding information
in the Content-Type header). Adding in a charset
that used the same encoding value as the linked stylesheet corrected the
problem, he reported.
User-contributed notes
- ID:
- #2
- Date:
- Mon, 04 Jan 2010 15:29:50 GMT
@AutisticCuckoo I tried to recreate the example you used, but for whatever reason all the parameters were not lining up and I couldn't get it to break, hence was unable to fix again using charset. However, I will update the reference with your wording, with caveats
- ID:
- #1
- Date:
- Wed, 12 Mar 2008 09:01:25 GMT
At least Firefox and Opera do honour this attribute, which can be evidenced if you use generated content. If the external style sheet uses a different character encoding than the document that links to it (and the server doesn't send encoding information in the Content-Type header), the generated content will be gibberish if it contains characters outside the US-ASCII repertoire. Adding a CHARSET attribute to the LINK element fixes the problem in FF2.0 and Opera 9.
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.