Accented Characters and Ligatures
in HTML and JavaScript

This page is moving! The permanent location will be at:
www.javascripter.net/faq/accentedcharacters.htm.

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.  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!
    

    This table lists the HTML entities, character codes, and URL-encodings for accented Latin letters and ligatures. (Some accented letters that do not have standard HTML entities. Still, those letters can be rendered, similar to the above example, 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.

  • 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.
    Not all letter/accent combinations are supported; the results will vary from browser to browser.

    See also:

  • How do I convert a string to URL encoding?
  • Greek Letters in HTML and JavaScript
  • Special Symbols and Mathematical Symbols
  • W3C Character Entity References in HTML 4 (www.w3.org)

    Copyright © 1999-2011, JavaScripter.net.