Accented Characters and Ligatures
|
Question: Can I display accented characters or ligatures as part of JavaScript output?
Answer: You can include accented characters and ligatures in JavaScript strings and/or display them on your HTML pages using the following encodings for the letters:
\xXX in JavaScript strings; e.g. ñ is \xF1
\uXXXX in JavaScript strings; e.g. š is \u0161
ñ and š is š
ñ and š is š
unescape with a suitable argument; e.g. ñ is unescape('%F1')
decodeURI with a suitable argument; e.g. ñ is decodeURI('%C3%B1')
Example 1: Here is a test for the capital letter U-umlaut (Ü):
document.write('\xDC') //
document.write('Ü') //
document.write('Ü') //
document.write(unescape('%DC')) //
document.write(decodeURI('%C3%9C')) //
Example 2: Here is a test for the Latin OE ligature (Œ):
document.write('\u0152') //
document.write('Œ') //
document.write('Œ') //
document.write(unescape('%u0152')) //
document.write(decodeURI('%C5%92')) //
To display an accented character in a JavaScript alert message or a confirm dialog box, use the hexadecimal code of the character, for example:
alert('\xC5ngstr\xF6m is a unit of length.') //Try it!
The following table lists the HTML entities, character codes, and URL-encodings for accented Latin letters and ligatures.
(Letters that do not have standard HTML entities are not included. Still, those letters can be rendered,
similar to the above examples, as long as you know the character codes
\xXX or \uXXXX or &#XXX;
e.g. the letters č and ℓ can be rendered using
č and ℓ respectively.)
See also
Greek letters,
Mathematical symbols and
URL-encoding.
| chr | HexCode | Numeric | HTML entity | Description | ||
|---|---|---|---|---|---|---|
| À | \xC0 | À | À | %C0 | %C3%80 | |
| Á | \xC1 | Á | Á | %C1 | %C3%81 | |
| Â | \xC2 | Â | Â | %C2 | %C3%82 | |
| Ã | \xC3 | Ã | Ã | %C3 | %C3%83 | |
| Ä | \xC4 | Ä | Ä | %C4 | %C3%84 | |
| Å | \xC5 | Å | Å | %C5 | %C3%85 | |
| Æ | \xC6 | Æ | Æ | %C6 | %C3%86 | |
| Ç | \xC7 | Ç | Ç | %C7 | %C3%87 | |
| È | \xC8 | È | È | %C8 | %C3%88 | |
| É | \xC9 | É | É | %C9 | %C3%89 | |
| Ê | \xCA | Ê | Ê | %CA | %C3%8A | |
| Ë | \xCB | Ë | Ë | %CB | %C3%8B | |
| Ì | \xCC | Ì | Ì | %CC | %C3%8C | |
| Í | \xCD | Í | Í | %CD | %C3%8D | |
| Î | \xCE | Î | Î | %CE | %C3%8E | |
| Ï | \xCF | Ï | Ï | %CF | %C3%8F | |
| Ð | \xD0 | Ð | Ð | %D0 | %C3%90 | |
| Ñ | \xD1 | Ñ | Ñ | %D1 | %C3%91 | |
| Ò | \xD2 | Ò | Ò | %D2 | %C3%92 | |
| Ó | \xD3 | Ó | Ó | %D3 | %C3%93 | |
| Ô | \xD4 | Ô | Ô | %D4 | %C3%94 | |
| Õ | \xD5 | Õ | Õ | %D5 | %C3%95 | |
| Ö | \xD6 | Ö | Ö | %D6 | %C3%96 | |
| Ø | \xD8 | Ø | Ø | %D8 | %C3%98 | |
| Ù | \xD9 | Ù | Ù | %D9 | %C3%99 | |
| Ú | \xDA | Ú | Ú | %DA | %C3%9A | |
| Û | \xDB | Û | Û | %DB | %C3%9B | |
| Ü | \xDC | Ü | Ü | %DC | %C3%9C | |
| Ý | \xDD | Ý | Ý | %DD | %C3%9D | |
| Þ | \xDE | Þ | Þ | %DE | %C3%9E | |
| ß | \xDF | ß | ß | %DF | %C3%9F | |
| à | \xE0 | à | à | %E0 | %C3%A0 | |
| á | \xE1 | á | á | %E1 | %C3%A1 | |
| â | \xE2 | â | â | %E2 | %C3%A2 | |
| ã | \xE3 | ã | ã | %E3 | %C3%A3 | |
| ä | \xE4 | ä | ä | %E4 | %C3%A4 | |
| å | \xE5 | å | å | %E5 | %C3%A5 | |
| æ | \xE6 | æ | æ | %E6 | %C3%A6 | |
| ç | \xE7 | ç | ç | %E7 | %C3%A7 | |
| è | \xE8 | è | è | %E8 | %C3%A8 | |
| é | \xE9 | é | é | %E9 | %C3%A9 | |
| ê | \xEA | ê | ê | %EA | %C3%AA | |
| ë | \xEB | ë | ë | %EB | %C3%AB | |
| ì | \xEC | ì | ì | %EC | %C3%AC | |
| í | \xED | í | í | %ED | %C3%AD | |
| î | \xEE | î | î | %EE | %C3%AE | |
| ï | \xEF | ï | ï | %EF | %C3%AF | |
| ð | \xF0 | ð | ð | %F0 | %C3%B0 | |
| ñ | \xF1 | ñ | ñ | %F1 | %C3%B1 | |
| ò | \xF2 | ò | ò | %F2 | %C3%B2 | |
| ó | \xF3 | ó | ó | %F3 | %C3%B3 | |
| ô | \xF4 | ô | ô | %F4 | %C3%B4 | |
| õ | \xF5 | õ | õ | %F5 | %C3%B5 | |
| ö | \xF6 | ö | ö | %F6 | %C3%B6 | |
| ø | \xF8 | ø | ø | %F8 | %C3%B8 | |
| ù | \xF9 | ù | ù | %F9 | %C3%B9 | |
| ú | \xFA | ú | ú | %FA | %C3%BA | |
| û | \xFB | û | û | %FB | %C3%BB | |
| ü | \xFC | ü | ü | %FC | %C3%BC | |
| ý | \xFD | ý | ý | %FD | %C3%BD | |
| þ | \xFE | þ | þ | %FE | %C3%BE | |
| ÿ | \xFF | ÿ | ÿ | %FF | %C3%BF | |
| Œ | \u0152 | Œ | Œ | %u0152 | %C5%92 | |
| œ | \u0153 | œ | œ | %u0153 | %C5%93 | |
| Š | \u0160 | Š | Š | %u0160 | %C5%A0 | |
| š | \u0161 | š | š | %u0161 | %C5%A1 | |
| Ÿ | \u0178 | Ÿ | Ÿ | %u0178 | %C5%B8 | |
| ƒ | \u0192 | ƒ | ƒ | %u0192 | %C6%92 |
Finally, if you cannot find the desired character, you can create one using the following combining accents:
Combining accent HexCode Numeric entity Example
Grave accent \u0300 ̀ document.write('à') //
Acute accent \u0301 ́ document.write('á') //
Circumflex accent \u0302 ̂ document.write('ê') //
Tilde \u0303 ̃ document.write('ã') //
Macron \u0304 ̄ document.write('ā') //
Breve \u0306 ̆ document.write('ă') //
Dot \u0307 ̇ document.write('ż') //
Diaeresis (umlaut) \u0308 ̈ document.write('ä') //
Hook \u0309 ̉ document.write('ả') //
Ring \u030A ̊ document.write('å') //
Double acute \u030B ̋ document.write('ő') //
Caron (haček) \u030C ̌ document.write('ž') //
There are over a hundred combining accents spanning the Unicode range from \u0300 to \u036F.
See also:
Copyright © 1999-2011, JavaScripter.net.