String.prototype.normalize()
normalize([form]) Returns:
string · Updated March 13, 2026 · String Methods string unicode normalization
The normalize() method returns the Unicode normalization form of the string. This is essential for comparing strings that may look identical but have different character compositions—like characters with accents that can be represented as single characters or as a base character plus combining marks.
Syntax
str.normalize([form])
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
form | string | "NFC" | The Unicode normalization form: "NFC", "NFD", "NFKC", or "NFKD" |
Normalization Forms
- NFC (Canonical Decomposition, Canonical Composition) — Default. Composes characters where possible.
- NFD (Canonical Decomposition) — Decomposes characters into their base + combining marks.
- NFKC (Compatibility Decomposition, Canonical Composition) — Similar to NFC but also normalizes compatibility characters.
- NFKD (Compatibility Decomposition) — Most aggressive decomposition.
Examples
Basic normalization with NFC
const str1 = "\u00E9"; // é as single character
const str2 = "e\u0301"; // e + combining acute accent
console.log(str1 === str2);
// false — they're visually identical but different code points
console.log(str1.normalize() === str2.normalize());
// true — normalize() makes them equal
Comparing user input
function normalizeInput(input) {
return input.normalize("NFC");
}
const user1 = normalizeInput("café");
const user2 = normalizeInput("café");
console.log(user1 === user2);
// true — works even if user typed differently
Using NFD for character analysis
const str = "résumé";
// NFC: keeps composed form
console.log(str.normalize("NFC").length);
// 6
// NFD: decomposes into base + combining marks
console.log(str.normalize("NFD").length);
// 8 (é becomes e + ́)
Searching within normalized strings
const words = ["café", "resume", "naïve"];
// Normalize both the search term and array elements
const searchTerm = "CAFÉ".toLowerCase().normalize("NFC");
const found = words.find(w =>
w.normalize("NFC").toLowerCase() === searchTerm
);
console.log(found);
// "café"
Common Patterns
Form selection guidelines:
- Use NFC for most cases—it’s what users expect and matches most text formats
- Use NFD when you need to count or manipulate individual character components
- Use NFKC/NFKD when dealing with legacy compatibility characters (like ligatures)
Database storage: Always normalize before storing Unicode strings to ensure consistent matching.
Search/compare: Normalize both strings before comparison to handle user variations gracefully.