Special Symbols and Math Symbolsin HTML and JavaScript

JavaScript FAQ | Numbers FAQ | Strings and RegExp FAQ  

Question: Can I display special or mathematical symbols as part of JavaScript output?

Answer: You can include symbols in JavaScript strings and/or display symbols on your HTML pages using several representations:

  • hexadecimal codes
    in JavaScript strings; e.g. degree (°) is
  • Unicode hex codes
    in JavaScript strings; e.g. euro sign (€) is
  • HTML entities; e.g. euro (€) is
    and degree (°) is
  • numeric HTML entities; e.g. euro (€) is
    and degree (°) is
  • unescape
    with a suitable argument; e.g. ° is
  • decodeURI
    with a suitable argument; e.g. ° is
    Example 1:  Most modern browsers correctly display the euro sign (€):
    document.write('\u20AC')               // 
    document.write('€')              // 
    document.write('€')               // 
    document.write(unescape('%u20AC'))     // 
    document.write(decodeURI('%E2%82%AC')) // 
    Example 2:  Here is a test for the plus-or-minus sign (±):
    document.write('\xB1')                 // 
    document.write('±')               // 
    document.write('±')             // 
    document.write(unescape('%B1'))        // 
    document.write(decodeURI('%C2%B1'))    // 

    To display a special symbol in a JavaScript alert message or a confirm dialog box, use the hexadecimal code of the symbol, for example:

    alert('The euro currency sign is \u20AC'); // Try it!

    The following table lists the HTML entities, character codes, and URL-encodings for mathematical and special symbols. (Symbols that do not have standard HTML entities are not included. You can still use those symbols too, similar to the above examples, as long as you know the correct character codes

    . See also Greek letters and URL-encoding.)
  • chr  HexCode   Numeric   HTML entity  escape(chr)  encodeURI(chr)   Description
    quotation mark
    less-than sign
    greater-than sign
    non-breaking space
    inverted exclamation mark
    cent sign
    pound sign
    currency sign
    yen sign = yuan sign
    broken vertical bar
    section sign
    diaeresis = spacing diaeresis
    copyright sign
    feminine ordinal indicator
    left-pointing double angle quotation mark = left pointing guillemet
    not sign
    soft hyphen = discretionary hyphen
    registered sign = registered trademark sign
    macron = spacing macron = overline = APL overbar
    degree sign
    plus-minus sign = plus-or-minus sign
    superscript two = superscript digit two = squared
    superscript three = superscript digit three = cubed
    acute accent = spacing acute
    micro sign
    pilcrow sign = paragraph sign
    middle dot = Georgian comma = Greek middle dot
    cedilla = spacing cedilla
    superscript one = superscript digit one
    masculine ordinal indicator
    right-pointing double angle quotation mark = right pointing guillemet
    vulgar fraction one quarter = fraction one quarter
    vulgar fraction one half = fraction one half
    vulgar fraction three quarters = fraction three quarters
    inverted question mark = turned question mark
    multiplication sign
    division sign
    latin small f with hook = function = florin
    modifier letter circumflex accent
    small tilde
    en space
    em space
    thin space
    zero width non-joiner
    zero width joiner
    left-to-right mark
    right-to-left mark
    en dash
    em dash
    left single quotation mark
    right single quotation mark
    single low-9 quotation mark
    left double quotation mark
    right double quotation mark
    double low-9 quotation mark
    double dagger
    bullet = black small circle
    horizontal ellipsis = three dot leader
    per mille sign
    prime = minutes = feet
    double prime = seconds = inches
    single left-pointing angle quotation mark
    single right-pointing angle quotation mark
    overline = spacing overscore
    fraction slash
    euro sign
    blackletter capital I = imaginary part
    script small L
    numero sign
    script capital P = power set = Weierstrass p
    blackletter capital R = real part symbol
    trademark sign
    alef symbol = first transfinite cardinal
    leftwards arrow
    upwards arrow
    rightwards arrow
    downwards arrow
    left right arrow
    downwards arrow with corner leftwards = carriage return
    leftwards double arrow
    upwards double arrow
    rightwards double arrow
    downwards double arrow
    left right double arrow
    for all
    partial differential
    there exists
    empty set = null set = diameter
    nabla = backward difference
    element of
    not an element of
    contains as member
    n-ary product = product sign
    n-ary sumation
    minus sign
    asterisk operator
    square root = radical sign
    proportional to
    logical and = wedge
    logical or = vee
    intersection = cap
    union = cup
    tilde operator = varies with = similar to
    approximately equal to
    almost equal to = asymptotic to
    not equal to
    identical to
    less-than or equal to
    greater-than or equal to
    subset of
    superset of
    not a subset of
    subset of or equal to
    superset of or equal to
    circled plus = direct sum
    circled times = vector product
    up tack = orthogonal to = perpendicular
    dot operator
    left ceiling = apl upstile
    right ceiling
    left floor = apl downstile
    right floor
    left-pointing angle bracket = bra
    right-pointing angle bracket = ket
    black spade suit
    black club suit = shamrock
    black heart suit = valentine
    black diamond suit

    See also:

  • How do I convert a string to URL encoding?
  • Can I display Greek letters on my page as part of JavaScript output?
  • Accented Characters and Ligatures
  • W3C Character Entity References in HTML 4 (www.w3.org)

    Copyright © 1996-2018, JavascriptFAQ.net.