Declaring a Style Sheet s Encoding


Declaring a Style Sheet's Encoding

Because style sheets are mostly made up of CSS properties and enumerated values, they don't often contain anything but ASCII text. However, there's no reason why the classes, ids, or even content couldn't contain non-ASCII characters. Especially in those cases, it's important to declare the style sheet's encoding (and save it properly as well, as described on page 333).

To declare a style sheet's encoding:

On the very first line of your style sheet, type @charset "code";, where code is the name of the encoding with which you saved the style sheet.

Tips

  • The encoding declaration must be the very first line of your CSS document.

  • Be sure to save your style sheet with the same encoding as the one you declare.

  • If your style sheet contains only ASCII characters, which is the norm for most English-language style sheets, declaring the encoding is not crucial.

  • Some font names include non-ASCII characters. In that case, it's a good idea to declare the style sheet's encoding.

  • You can include individual escaped non-ASCII characters in a style sheet without worrying too much about the encoding. Use \hex, where hex is the hexadecimal number that refers to the desired character and there is a space at the end. This is analogous to using character references in (X)HTML documents as described in more detail on page 336.


Figure 21.9. Because this style sheet includes id names with non-ASCII characters, you should declare its encoding in the very first line.





HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net