Jump to content

<meta http-equiv=""> good practice, need advice


nomnex

Recommended Posts

This is a general question. What is the best choice and why?

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

or

<meta http-equiv="Content-Type" content="text/html;charset=utf-16">

(what difference -- more practical than technical, or I might not understand -- between utf-8 and utf-16?or

<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">

On a w3s page says:

Tip: All HTML 4 processors already support UTF-8, and all XHTML and XML processors support UTF-8 and UTF-16!
But what's a HTML 4 processors? is it the browser engine?
Link to comment
Share on other sites

Yes, an HTML 4 processor is a browser.Often it's best to send a header from the server aside from the <meta> tag, because the browser doesn't always pay attention to the <meta> tag. A <meta> tag is only a suggestion.UTF-16 has a larger range of characters than UTF-8, but UTF-8 has tens of thousands in itself.If you use an encoding such as ISO-8859-1 you're limited to a maximum of 256 different characters on the page. Multibyte characters like in UTF-8 will actually be displayed at multiple characters.

Link to comment
Share on other sites

AFAIK, UTF-8 and UTF-16 can both represent any unicode character. It's just that UTF-8 uses 8 bits (i.e. one byte) to represent an octet (I'm not sure if that was the exact term...), whereas UTF-16 uses 16 bits for the same purpose. Either way, to form a character, several octets need to be present in a "byte sequence".So, with that said, UTF-8 is generally a better choice than UTF-8, because it can represent any character and it takes less space for latin characters and is available in more environments. UTF-16 can represent chinese characters with less space, which is why the chinese often choose it over UTF-8. UTF-16 is available in all modern environments, but may not be available in some legacy ones (that appeared at the time of UTF-8, and not UTF-16).As for the meta vs HTTP header... this isn't a "vs" thinhg. It's best to have both - HTTP header for online view and meta for offline view (e.g. if someone saves your page).BTW, it's not just you who is limited - so are your site's users. If you accept any user input, not using a UTF encoding means you're basically forcing them to write latin characters only. And to think there are actually characters like © which are universally understood in any language, but are not available in most encodings (using the © entity is just a workaround in HTML context)...

Link to comment
Share on other sites

Ingolme, boen_robot, thanks for your answers.

So, with that said, UTF-8 is generally a better choice than UTF-8, because it can represent any character and it takes less space for latin characters and is available in more environments.
do you mean UTF-8 is better than UTF-16 or the opposite?
As for the meta vs HTTP header... this isn't a "vs" thinhg. It's best to have both - HTTP header for online view and meta for offline view (e.g. if someone saves your page).
I am completing the w3s HTML tutorial advanced. I have done the topic about META tag. It does not go into details. Could you, or Ingolme, show me how to tag correctly the meta + HTTP header with the encoding information in an example? Thank you in advanced.
BTW, it's not just you who is limited - so are your site's users. If you accept any user input, not using a UTF encoding means you're basically forcing them to write latin characters only. And to think there are actually characters like © which are universally understood in any language, but are not available in most encodings (using the © entity is just a workaround in HTML context)...
I see, so it makes sens to use either utf-8, either utf-16 (I have never seen a utf-16 encoded web page yet, though, probably for the reasons cited by Inglome - larger size than UTF-8 to display roman characters).
Link to comment
Share on other sites

do you mean UTF-8 is better than UTF-16 or the opposite?
Yes... sorry... I meant UTF-8 is better than UTF-16 in most cases.
I am completing the w3s HTML tutorial advanced. I have done the topic about META tag. It does not go into details. Could you, or Ingolme, show me how to tag correctly the meta + HTTP header with the encoding information in an example? Thank you in advanced.
The meta with charset is exactly what you're doing in the first post. The HTTP header is not set in HTML. It's set by the server. If you're using a server side scripting language, say, PHP, you can use it to make the server send such a header. The header itself looks pretty similar to what you see in the meta.See PHP's header() function for an example. For this particular purpose, the header would look like:
header('Content-Type: text/html;charset=UTF-8');

Link to comment
Share on other sites

The meta with charset is exactly what you're doing in the first post. The HTTP header is not set in HTML. It's set by the server. If you're using a server side scripting language, say, PHP, you can use it to make the server send such a header.
I see, that's clearer now. Thank you. I keep the HTTP header sever side in mind until I reach the PHP w3s tutorial.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...