JavaScript EditorBest javascript editor debugger     Ajax website 

Main Page

Previous Page
Next Page

Declaring the Encoding

All text documents, (X)HTML files included, are saved with a character encoding. Since there are many encodings in use in the world, it's a good idea to declare which encoding your page was saved in right in the (X)HTML code. This makes it easier for browsers on systems with different default encodings to view the characters in your pages correctly.

To declare the character encoding:

In the head section of your page, type <meta http-equiv="content-type" content="text/html; charset=utf-8" />, where encoding is the character encoding with which you saved the file.

Your Web page's character encoding depends on the way you saved it. If you saved it in a text-only formatand didn't choose a special encodingit's a safe bet that your document was saved with the default encoding for your language. For example, the default encoding for English Windows is windows-1252 and for English Macintosh is x-mac-roman.

Figure 3.4. I've saved my files in Unicode, with the UTF-8 encoding. (This is BBEdit. For more details about saving files with encodings other than the default for your system, consult Chapter 21, Symbols and Non-English Characters.)

Figure 3.5. When the visitor's browser sees this meta tag, it will know that the page was encoded with UTF-8, and will display it properly. The key is that the encoding that you declare in the meta tag match the one with which you actually saved the file.


  • While an encoding is not technically required by the specs, I strongly recommend you declare one.

  • If you chose a particular encoding upon saving the file, that's the encoding you should use in the meta tag.

  • You can find a list of common character set codes at

  • XHTML requires that you declare the encoding if it is anything other than the default UTF-8 or UTF-16.

  • For more about encodings, see Chapter 21, Symbols and Non-English Characters.

Previous Page
Next Page

JavaScript EditorBest javascript editor debugger     Ajax website