This article explains how to resolve issues with accented characters in JavaScript when they do not display correctly in functions like alert().
Important: This solution is aimed at advanced users or those with programming knowledge. Before using Unicode escapes, verify that your page declares UTF-8 (<meta charset="UTF-8">) and that the .js file is saved in UTF-8.
Problem
When inserting strings with JavaScript (for example in alert()), accents may look incorrect. HTML entities like á do not work inside JavaScript strings: you must use the direct character in UTF-8 or its Unicode escape.
Solution — Unicode Escapes
Use the format \uXXXX, where each X is a hexadecimal digit.
Example:
// Instead of:
alert("cartograf\u00EDa"); // cartografía
// Or with the direct UTF-8 character (if the file is UTF-8):
alert("cartografía");
For lowercase í: \u00ED
Spanish characters
| Character | HTML | Unicode (JS) |
|---|---|---|
| Á | Á | \u00C1 |
| á | á | \u00E1 |
| É | É | \u00C9 |
| é | é | \u00E9 |
| Í | Í | \u00CD |
| í | í | \u00ED |
| Ó | Ó | \u00D3 |
| ó | ó | \u00F3 |
| Ú | Ú | \u00DA |
| ú | ú | \u00FA |
| Ü | Ü | \u00DC |
| ü | ü | \u00FC |
| Ñ | Ñ | \u00D1 |
| ñ | ñ | \u00F1 |
Other special characters
| Character | HTML | Unicode (JS) |
|---|---|---|
| & | & | \u0026 |
| < | < | \u003C |
| > | > | \u003E |
| " | " | \u0022 |
| ' | ' | \u0027 |
| NBSP space | | \u00A0 |
| © | © | \u00A9 |
| ® | ® | \u00AE |
| € | € | \u20AC |
| ¼ | ¼ | \u00BC |
| ½ | ½ | \u00BD |
| ¾ | ¾ | \u00BE |
Need help?
If the issue persists on your hosted site, contact technical support from the client portal or the site's online chat.
