Unicode works across the web when each layer receives the representation it expects. This checklist shows how to insert and escape symbols or emoji in HTML, CSS, JavaScript, JSON, and URLs while avoiding broken glyphs, invalid strings, inaccessible controls, and misleading character counts.
Overview
Unicode is the character system used to represent writing systems, symbols, punctuation, emoji, and many other forms of text. The same character can be written literally or represented with an escape, but the correct syntax depends on the format handling it.
For example, HTML understands character references, CSS uses a backslash followed by hexadecimal digits, JavaScript supports Unicode code point escapes, and JSON commonly uses either literal Unicode text or \u escapes. A URL is different again: its text is encoded as UTF-8 bytes and then percent-encoded where required.
Before choosing an escape, identify the boundary where the text will be interpreted:
- HTML: Use literal UTF-8 text or a named or numeric character reference.
- CSS: Use a CSS hexadecimal escape, such as
\1F600, often followed by a space when another hexadecimal character could be mistaken for part of the escape. - JavaScript: Prefer a code point escape such as
\u{1F600}when the environment supports modern JavaScript syntax. A surrogate pair is the older alternative. - JSON: Use literal Unicode in a UTF-8 document or a JSON escape such as
\u263A. Characters outside the Basic Multilingual Plane may require two UTF-16 escape units when written in escaped form. - URLs: Encode the complete parameter value as UTF-8 percent-encoded data rather than replacing a character with its Unicode code point number.
Literal characters are often the clearest choice in source files that are reliably stored and served as UTF-8. Escapes are useful when a format requires them, when a character is difficult to see, or when a test fixture needs to make the underlying value explicit. For a broader comparison of syntax, see Unicode in HTML, CSS, JavaScript, and JSON: Choosing the Right Character Escape.
Checklist by scenario
Adding a symbol to HTML
- Save the document as UTF-8 and declare the character encoding appropriately.
- Prefer the literal character when it improves readability:
<p>โ Complete</p>. - Use a numeric character reference when needed:
✓or✓. - Use a named entity only when the name is supported and its meaning is clear, such as
&for an ampersand. - Escape reserved HTML syntax. An ampersand in text may need
&, and a less-than sign may need<.
Do not assume that an HTML entity is a general-purpose Unicode escape. A string containing 😀 is interpreted by an HTML parser, but the same text in a JavaScript string or JSON payload remains ordinary text unless that format processes it.
Using a symbol in CSS
CSS content and generated labels can use hexadecimal escapes:
.status::before {
content: "\2713";
}
.celebrate::before {
content: "\1F389 ";
}
The trailing space in the second example terminates the CSS escape. It is consumed as part of the escape syntax rather than displayed. If the next character is not hexadecimal, a terminating space may not be necessary, but using one deliberately can prevent ambiguity. Test the result with the actual font stack: a valid code point can still appear as a missing-glyph box if no selected font provides a glyph.
For meaningful interface text, do not rely on content alone. Generated content can be difficult for assistive technology and should not replace an accessible label or visible text. See the guide to CSS Unicode ranges and font fallback when a symbol displays inconsistently.
Writing emoji or symbols in JavaScript
Modern JavaScript can represent a Unicode code point directly or with a code point escape:
const check = "โ";
const party = "\u{1F389}";
console.log(check); // โ
console.log(party); // ๐
The older form uses UTF-16 surrogate pairs. For example, \uD83C\uDF89 represents the same party popper as \u{1F389}. Prefer the code point form when your supported JavaScript syntax allows it because it is easier to read and less prone to pairing mistakes.
Remember that JavaScript string length counts UTF-16 code units, not necessarily user-perceived characters. A single emoji may have a length greater than one, and a family emoji or an emoji with a skin-tone modifier may contain several code points. Use Array.from(value) or the spread operator for a basic code-point iteration, and use Intl.Segmenter where user-perceived grapheme clusters matter.
Putting Unicode in JSON
JSON can contain literal Unicode text when the file or transport is handled as UTF-8:
{
"status": "โ Complete",
"message": "ใใใซใกใฏ"
}
It can also use JSON escapes for selected characters:
{
"status": "\u2713 Complete"
}
When producing JSON in application code, serialize values with the language's JSON encoder instead of assembling JSON by concatenating strings. This handles quotation marks, backslashes, control characters, and other syntax-sensitive data. After encoding, parse the result again in a test or validation step to confirm that the payload is valid JSON and that the decoded value is what the receiver expects.
Encoding Unicode in URLs
URL encoding is byte-oriented. Encode a parameter value with the platform's URL API rather than manually converting a code point:
const url = new URL("https://example.com/search");
url.searchParams.set("q", "cafรฉ ๐");
console.log(url.toString());
In browser code, encodeURIComponent can be appropriate for an individual component, while URL and URLSearchParams help keep complete URLs and query parameters separate. Avoid encoding an entire URL as though it were one parameter, and avoid encoding a value more than once.
What to double-check
- Encoding declarations: Confirm that the source file, server response, database connection, and API client agree on UTF-8. A correct character can become replacement characters before your application receives it.
- Font coverage: Check the real browser, operating system, and fallback stack. Emoji appearance is supplied by fonts and platforms, so visual design can vary.
- Variation selectors: Some emoji-related sequences use variation selectors to request text or emoji presentation. Do not delete invisible characters from a string without understanding their role. The guide to emoji sequences covers variation selectors, zero-width joiners, and skin-tone modifiers.
- Grapheme clusters: What users perceive as one character may contain multiple code points. Cursor movement, deletion, truncation, and maximum-length validation should be tested with combining marks, accented text, flags, and joined emoji.
- Accessibility: Give an icon-only button an accessible name. Treat decorative emoji as decorative, and do not make color or emoji the only way to communicate status.
- Normalization: Visually identical text can have different underlying sequences, such as a precomposed accented letter versus a letter followed by a combining mark. Normalize only when it matches the application's comparison and storage requirements.
- Regular expressions: A dot, character class, or length assertion may not correspond to a user-perceived character. For Unicode-aware matching, review the language's Unicode and property-escape support.
For repeatable testing, maintain fixtures containing multilingual text, combining marks, symbols, emoji sequences, and intentionally malformed input. A dedicated Unicode test corpus makes regressions easier to reproduce.
Common mistakes
- Using the wrong escape language: An HTML entity is not automatically valid in CSS, JavaScript, or JSON. Escape at the layer that parses the value.
- Dropping the CSS terminator: A CSS escape followed by hexadecimal text may consume more characters than intended. Add a separating space or use a clearly delimited form.
- Splitting surrogate pairs: Treating each UTF-16 unit as an independent character can produce invalid text. Prefer code point escapes and test supplementary characters.
- Counting code units as characters: JavaScript's
lengthproperty is not a reliable user-visible character count for emoji or many non-BMP characters. - Manually building JSON: Concatenating unescaped user input can create invalid JSON or alter its structure. Use a serializer.
- Confusing code points with URL encoding: A URL parameter needs UTF-8 percent encoding, not a string such as
%1F600. - Using emoji as essential UI icons: Emoji vary by platform and may have different visual emphasis or meaning. Use a controlled icon or text label for critical actions.
- Normalizing or stripping invisible characters blindly: Variation selectors, joiners, and combining marks can change what a sequence displays or how it compares.
When to revisit
Return to this checklist whenever you add a new language, symbol set, emoji feature, import format, or URL parameter. It is especially useful before seasonal planning cycles if your product publishes event names, campaign labels, or date-related emoji that may be copied between systems.
Recheck the implementation when a browser, JavaScript runtime, database driver, frontend framework, font package, or build pipeline changes. Also revisit it when users report a missing glyph, incorrect truncation, failed search, broken URL, or inconsistent display across devices. Browser and runtime support can evolve, and Unicode data used by libraries may be updated independently of your application code.
Use this final action list before shipping:
- Identify the exact layer: HTML, CSS, JavaScript, JSON, or URL.
- Choose literal UTF-8 text or that layer's documented escape syntax.
- Test both ordinary symbols and a multi-code-point example.
- Inspect fonts, fallback behavior, accessible names, and rendered output.
- Verify serialization, parsing, URL round-tripping, and user-visible length rules.
- Keep representative Unicode fixtures in automated tests so a toolchain change exposes a regression quickly.