Wais Kamal
Wais Kamal

Reputation: 6210

Different character encoding for some HTML elements

Is it possible to change the character encoding of one HTML element without changing the character encoding of the whole page? For example, I have this line:

<meta charset="utf-8">

Can I do this?

<span charset="windows-1252">Content here</span>

Upvotes: 3

Views: 684

Answers (2)

ElementW
ElementW

Reputation: 850

While the HTML5 standard has a section named 12.2.2.4 Changing the encoding while parsing, this section specifies in a note this only happens with <meta> tags that changes encoding, which can only appear once, in the first 1024 bytes of the document.

So, it is not possible to change the encoding for a specific part of the HTML document.

Although not worded the same way, earlier versions of HTML, as well as XHTML, have the same kind of restrictions, preventing you from changing the encoding mid-document.

Upvotes: 2

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201886

No. An HTML document as a whole has a character encoding. It is detected by browsers in a rather complicated manner, and this may involve reading an initial part of it using one encoding, then selecting another one after e.g. a suitable meta tag is encountered. But in that case the browser re-reads the document using the encoding so determined.

Upvotes: 3

Related Questions