3. Specify a character set

The character encoding tells the browser what character set the web page is written in. If the character set has not been specified, the browser will assume that the web page uses a default one. If it guesses wrong, your page may be displayed incorrectly. To avoid this, use one of the below methods to specify the character set your pages are encoded in.

Guidelines:

  1. Send the char set parameter in the content type header of HTTP
  2. This is the most efficient method to set the character set, because you don't need to set it for every page. Set your server to send a Content-Type header for all documents it serves that are of type text/html.



    Example 1:


    Content-Type: text/html; charset=UTF-8

  3. For HTML or XHTML served as HTML, you should always use the < meta > tag inside < head >.

If you don't control the server, you will need to set the character encoding manually for every page. You can do this with a Meta tag:

Example 2:

< meta http-equiv="content-type" content="text/html” charset=”utf-8" >

For XHTML, you need a slash at the end:

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

  • For XML (including XHTML), use the encoding pseudo-attribute in the XML declaration at the start of a document or the text declaration at the start of an entity.

Example 3:

< ?xml version="1.0" encoding="utf-8" ? >