To type a character that's not on your keyboard, you need its unicode codepoint in decimal or hexadecimal. In the examples below, HH means two hexadecimal digits, DD means two decimal digits, HHHH is four hexadecimal digits, and so on. DD+ means two or more decimal digits, HH+ means two or more hexadecimal digits.
HTML
To type out unicode characters in HTML, use one of the following:- &#DDD+;
- &#xHHH+;
Ɖ == Ɖ Ɖ == Ɖ ‡ == ‡
JavaScript
To type out unicode characters in JavaScript, use the following:- \uHHHH
== \u2021
CSS
To print out a unicode character using CSS content, use the following:- \HH+
== \2021(Note: the CSS example that I've used here only works in browsers that support the
:before pseudo class and the content rule, but in general you can use unicode characters anywhere in CSS.)URL
URL context is different from HTML context, so I'm including it here.To print a unicode character into a URL, you need to represent it in UTF-8, using the %HH notation for each byte.
eg:
‡ == %E2%80%A1 л == %D0%BB ' == %39This is not something that you want to do by hand, so use a library to do the conversion. In JavaScript, you can use the
encodeURI or encodeURIComponent functions to do this for you.End notes
Use escape sequences only in two cases.- Your editor or keyboard doesn't allow you to type the characters in directly.
- The characters could be misinterpreted as syntax, eg < or > in HTML.
References and Further Reading
- List of Unicode Characters on WikiPedia
- UTF-8 on WikiPedia
- Unicode and HTML on WikiPedia
- JavaScript Unicode Escape Sequences on Mozilla Developer Network
- Richard Ishida. 2005. Using Character Escapes in Markup and CSS in W3C Internationalisation.