Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > HTML/XHTML

  • Print
  • + Share This
This chapter is from the book

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=encoding" />, 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 format—and didn't choose a special encoding—it'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

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

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.

  • + Share This
  • 🔖 Save To Your Account