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

Home > Articles

  • 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.

bbbedit_utf-8.jpg

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 20, Symbols and Non-English Characters.)

Example 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.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="

   content-type" content="text/html; charset=utf-8" />


</head>
<body>


</body>
</html>
  • + Share This
  • 🔖 Save To Your Account