HTML and CSS Reference
In-Depth Information
The interesting thing to note is that most browsers look for character encoding
metadata only within the first 512 bytes of the page. Hence, you need to ensure that
if you have a lot of data in your <head> element, this meta element occurs before
everything else.
In the absence of charset encoding information, browsers have to guess which
charset encoding to apply. The HTML5 spec outlines the sniffing algorithm that
all browsers must implement at
tipage/parsing.html#encoding-sniffing-algorithm . Unfortunately, older browsers had
their own mechanisms for guessing character encoding.
In the case of Internet Explorer 7 and below, the default character encoding prefer-
ence is typically set to Auto Select . This means the browser scans the content of
the page to detect what character encoding would best apply. In case of Internet Ex-
plorer, if it finds a UTF-7 string within 4096 characters of the page, it would assume
the page uses UTF-7 encoding and your page will become vulnerable to cross-site
scripting attacks using UTF-7 encoding. Hence, the meta element declaration and
right on top of the page in the index.html page.
Note that if your server sends an HTTP header that is of a different encoding, then
that would take precedence. Make sure your server is set up to serve the right char-
set encoding as an HTTP header.
The HTML Doctype
Before the standardization of HTML and CSS, most markup and styles did not
render consistently in any browser. But when we had standards about how markup
should be written and more and more developers started adopting these standards,
browsers then had to face the problem of detecting which of the pages on the Inter-
net conformed to these standards and which weren't.
The Doctype was invented so that developers could inform the browser to render
the page using the newer standards mode. Without a Doctype declaration, browsers
would render the page in what is known as Quirks Mode (the way browsers used to
render the pages before standards became an acceptable practice). In IE6, having
a comment or an XML namespace declaration above the Doctype would render the
page in Quirks Mode too. In the early 2000s when using the XHTML Doctype with
Search WWH ::

Custom Search