09 December, 2010

Displaying special characters in your HTML and JavaScript

Occasionally I have the need to display umlauts or other non-standard Latin and Kanji characters in my HTML, JavaScript, and as a URL parameter. Each form have their own rules for encoding the characters to display correctly.
  • HTML: Use the HTML name or HTML number. For example & and " for ampersand and quote, respectively.
  • JavaScript: Use the Unicode equivalent. For example \u00E4 and \u00FC to add an umlaut over an 'a' or 'u', respectively.
  • URL Parameter: Use HEX codes. For example, %20 and %2F for a space and forward slash, respectively.
Here's a great reference from ascii.cl for the necessary codes.

No comments: