Skip to content

Instantly share code, notes, and snippets.

@mig1098
Last active February 27, 2024 21:18
Show Gist options
  • Save mig1098/d470d78415f4ff2fc5a5b46ff371e0d3 to your computer and use it in GitHub Desktop.
Save mig1098/d470d78415f4ff2fc5a5b46ff371e0d3 to your computer and use it in GitHub Desktop.
javascript unicode accents
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:
hexadecimal codes \xXX in JavaScript strings; e.g. ñ is \xF1
Unicode hex codes \uXXXX in JavaScript strings; e.g. š is \u0161
HTML entities; for example, ñ is ñ and š is š
numeric HTML entities; e.g. ñ 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 escape(chr) encodeURI(chr) Description
À \xC0 À À %C0 %C3%80 latin capital letter A with grave
Á \xC1 Á Á %C1 %C3%81 latin capital letter A with acute
 \xC2   %C2 %C3%82 latin capital letter A with circumflex
à \xC3 à à %C3 %C3%83 latin capital letter A with tilde
Ä \xC4 Ä Ä %C4 %C3%84 latin capital letter A with diaeresis
Å \xC5 Å Å %C5 %C3%85 latin capital letter A with ring above
Æ \xC6 Æ Æ %C6 %C3%86 latin capital ligature AE
Ç \xC7 Ç Ç %C7 %C3%87 latin capital letter C with cedilla
È \xC8 È È %C8 %C3%88 latin capital letter E with grave
É \xC9 É É %C9 %C3%89 latin capital letter E with acute
Ê \xCA Ê Ê %CA %C3%8A latin capital letter E with circumflex
Ë \xCB Ë Ë %CB %C3%8B latin capital letter E with diaeresis
Ì \xCC Ì Ì %CC %C3%8C latin capital letter I with grave
Í \xCD Í Í %CD %C3%8D latin capital letter I with acute
Î \xCE Î Î %CE %C3%8E latin capital letter I with circumflex
Ï \xCF Ï Ï %CF %C3%8F latin capital letter I with diaeresis
Ð \xD0 Ð Ð %D0 %C3%90 latin capital letter ETH
Ñ \xD1 Ñ Ñ %D1 %C3%91 latin capital letter N with tilde
Ò \xD2 Ò Ò %D2 %C3%92 latin capital letter O with grave
Ó \xD3 Ó Ó %D3 %C3%93 latin capital letter O with acute
Ô \xD4 Ô Ô %D4 %C3%94 latin capital letter O with circumflex
Õ \xD5 Õ Õ %D5 %C3%95 latin capital letter O with tilde
Ö \xD6 Ö Ö %D6 %C3%96 latin capital letter O with diaeresis
Ø \xD8 Ø Ø %D8 %C3%98 latin capital letter O with stroke
Ù \xD9 Ù Ù %D9 %C3%99 latin capital letter U with grave
Ú \xDA Ú Ú %DA %C3%9A latin capital letter U with acute
Û \xDB Û Û %DB %C3%9B latin capital letter U with circumflex
Ü \xDC Ü Ü %DC %C3%9C latin capital letter U with diaeresis
Ý \xDD Ý Ý %DD %C3%9D latin capital letter Y with acute
Þ \xDE Þ Þ %DE %C3%9E latin capital letter THORN
ß \xDF ß ß %DF %C3%9F latin small letter sharp s = ess-zed
à \xE0 à à %E0 %C3%A0 latin small letter a with grave
á \xE1 á á %E1 %C3%A1 latin small letter a with acute
â \xE2 â â %E2 %C3%A2 latin small letter a with circumflex
ã \xE3 ã ã %E3 %C3%A3 latin small letter a with tilde
ä \xE4 ä ä %E4 %C3%A4 latin small letter a with diaeresis
å \xE5 å å %E5 %C3%A5 latin small letter a with ring above
æ \xE6 æ æ %E6 %C3%A6 latin small ligature ae
ç \xE7 ç ç %E7 %C3%A7 latin small letter c with cedilla
è \xE8 è è %E8 %C3%A8 latin small letter e with grave
é \xE9 é é %E9 %C3%A9 latin small letter e with acute
ê \xEA ê ê %EA %C3%AA latin small letter e with circumflex
ë \xEB ë ë %EB %C3%AB latin small letter e with diaeresis
ì \xEC ì ì %EC %C3%AC latin small letter i with grave
í \xED í í %ED %C3%AD latin small letter i with acute
î \xEE î î %EE %C3%AE latin small letter i with circumflex
ï \xEF ï ï %EF %C3%AF latin small letter i with diaeresis
ð \xF0 ð ð %F0 %C3%B0 latin small letter eth
ñ \xF1 ñ ñ %F1 %C3%B1 latin small letter n with tilde
ò \xF2 ò ò %F2 %C3%B2 latin small letter o with grave
ó \xF3 ó ó %F3 %C3%B3 latin small letter o with acute
ô \xF4 ô ô %F4 %C3%B4 latin small letter o with circumflex
õ \xF5 õ õ %F5 %C3%B5 latin small letter o with tilde
ö \xF6 ö ö %F6 %C3%B6 latin small letter o with diaeresis
ø \xF8 ø ø %F8 %C3%B8 latin small letter o with stroke
ù \xF9 ù ù %F9 %C3%B9 latin small letter u with grave
ú \xFA ú ú %FA %C3%BA latin small letter u with acute
û \xFB û û %FB %C3%BB latin small letter u with circumflex
ü \xFC ü ü %FC %C3%BC latin small letter u with diaeresis
ý \xFD ý ý %FD %C3%BD latin small letter y with acute
þ \xFE þ þ %FE %C3%BE latin small letter thorn
ÿ \xFF ÿ ÿ %FF %C3%BF latin small letter y with diaeresis
Π\u0152 ΠΠ%u0152 %C5%92 latin capital ligature OE
œ \u0153 œ œ %u0153 %C5%93 latin small ligature oe
Š \u0160 Š Š %u0160 %C5%A0 latin capital letter S with caron
š \u0161 š š %u0161 %C5%A1 latin small letter s with caron
Ÿ \u0178 Ÿ Ÿ %u0178 %C5%B8 latin capital letter Y with diaeresis
ƒ \u0192 ƒ ƒ %u0192 %C6%92 latin small f with hook
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('ž') // ž
Unicode chr
\u00e1 = á
\u00e9 = é
\u00ed = í
\u00f3 = ó
\u00fa = ú
\u00c1 = Á
\u00c9 = É
\u00cd = Í
\u00d3 = Ó
\u00da = Ú
\u00f1 = ñ
\u00d1 = Ñ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment