Normalize Unicode text with Java Normalizer.Form.NFD
What Java's Normalizer.Form.NFD changes in Unicode text, how it differs from NFC, NFKD and NFKC, and when decomposed text is or isn't safe to store, compare or share.
Java's java.text.Normalizer class with Normalizer.Form.NFD converts a string into Unicode Normalization Form D, or canonical decomposition. It is not a styling effect, a reversal or a font. It changes which code points represent the text while keeping the text canonically equivalent to the original. This review covers what that change does, when it helps, and when you should keep or return to the composed form.
Short verdict: is NFD suitable for your use?
NFD is well suited as an intermediate processing step. It is useful when you need to separate base letters from accents, compare strings that may have been typed or imported in different ways, or inspect exactly which combining marks a string contains. Its main benefit is predictability: every canonically equivalent input produces the same decomposed output.
The decisive tradeoff is that NFD text is longer and less common as an interchange format. A precomposed letter such as é becomes two code points, so string lengths, substring offsets and byte counts change. Much web content and many other systems use the composed form, and W3C guidance for web content generally favors NFC. For storage, display, sharing and most interchange, the composed form (NFC) or the original text is usually the better choice. Use NFD for internal processing and convert back to NFC before output unless a destination specifically expects decomposed text.
What NFD actually changes
NFD applies canonical decomposition. Precomposed characters are split into a base character followed by one or more combining marks, and those marks are put into a standard canonical order. The stored code points change, but the text's meaning under Unicode is the same. Well-behaved renderers should display NFD and NFC versions of the same text identically.
- Accented Latin letters split apart: é (U+00E9) becomes e (U+0065) followed by the combining acute accent (U+0301).
- Multiple combining marks attached to one base letter are reordered into canonical order, so different input orderings that mean the same thing converge.
- Precomposed Hangul syllables decompose into their conjoining jamo.
- Compatibility characters are left alone: the ligature fi (U+FB01), full-width letters and mathematical styled letters such as bold or script "fonts" are not converted to plain letters by NFD.
- No character is visually mirrored, reversed or restyled, and reading direction is unaffected.
The point about compatibility characters matters if you arrived here looking for a way to undo Unicode "fancy text". Decorative alphabets built from mathematical alphanumeric symbols are separate characters with compatibility mappings. NFD keeps them as they are. NFKD or NFKC would map many of them to ordinary letters, but those forms also discard formatting distinctions that may matter, so they are a deliberate, lossy choice rather than a cleanup default.
How the four normalization forms compare
| Form | What it does | é (U+00E9) | fi ligature (U+FB01) |
| NFC | Canonical decomposition, then canonical composition | U+00E9 | unchanged |
| NFD | Canonical decomposition only | U+0065 U+0301 | unchanged |
| NFKC | Compatibility decomposition, then canonical composition | U+00E9 | f i |
| NFKD | Compatibility decomposition only | U+0065 U+0301 | f i |
Using Normalizer.Form.NFD in Java
The API is a static call that takes any CharSequence and a form, and returns a new String. Normalizer.isNormalized checks whether text is already in a given form. Using a Unicode escape in the source avoids ambiguity about whether your editor saved the literal as composed or decomposed.
import java.text.Normalizer;
String input = "Caf\u00E9"; // precomposed é
String nfd = Normalizer.normalize(input, Normalizer.Form.NFD);
System.out.println(input.length()); // 4
System.out.println(nfd.length()); // 5
System.out.println(input.equals(nfd)); // false
System.out.println(Normalizer.isNormalized(nfd, Normalizer.Form.NFD)); // true
nfd.codePoints().forEach(cp -> System.out.printf("U+%04X ", cp));
// U+0043 U+0061 U+0066 U+0065 U+0301
Normalization is idempotent: running NFD on text that is already in NFD returns the same text. The exact set of decompositions depends on the Unicode version supported by your JDK release, so very recently added characters may behave differently across Java versions.
The common accent-stripping pattern and its limits
A widespread use of NFD is removing diacritics for search keys or simplified identifiers: decompose, then delete combining marks.
String folded = Normalizer.normalize(input, Normalizer.Form.NFD)
.replaceAll("\\p{M}", "");
// "Caf\u00E9" -> "Cafe"
This is a lossy transformation, not a normalization. It changes meaning in languages where the accent distinguishes words, and it is incomplete: letters such as ø, ł, đ and ß have no canonical decomposition, so they pass through unchanged. In scripts where combining marks carry vowels or other essential information, deleting all marks can make text unreadable. Keep the original text and store the folded version only as a separate matching key.
NFD and text reversal
If you are decomposing text as part of a reverse-text workflow, be careful. StringBuilder.reverse keeps surrogate pairs together, but it does not keep combining sequences together. After NFD, the accent follows its base letter, so a naive reversal places U+0301 before the e, where it will attach to the wrong character or display on its own. Multi-code-point emoji, such as sequences joined with zero-width joiners or modified by skin-tone selectors, break apart in the same way. Reversal should operate on user-perceived characters (grapheme clusters), for example with java.text.BreakIterator.getCharacterInstance, and NFD makes this problem larger rather than smaller.
Will NFD text stay readable and usable after copying or sharing?
In principle, yes for reading and no guarantee for everything else. Because NFD output is canonically equivalent to the input, conforming software should render it the same and treat it as the same text. In practice, behavior depends on the destination, and no specific application, browser, platform or screen reader was tested for this review.
- Display: most modern renderers position combining marks correctly, but fonts or older software that lack proper mark positioning may show the accent offset or as a separate glyph. Check your actual destination.
- Copy and paste: the decomposed code points are normally copied as-is. Some systems, keyboards or editors may recompose text to NFC on input or save, so you should not assume NFD survives a round trip.
- Search and comparison: exact string matching fails between NFC and NFD versions of the same word, as String.equals shows above. Any system that does not normalize before comparing will treat them as different, which can break lookups, deduplication, database keys and file name matching.
- Editing: cursor movement and deletion may treat the base letter and the mark as separate units in some editors, so a single backspace can remove only the accent.
- Length limits: character and byte counts increase, which can affect validation rules, column widths and limits on fields such as user names.
- Accessibility: assistive technologies are expected to handle canonically equivalent text consistently, but this was not verified here. Where screen-reader output matters, test with the specific tool and configuration your audience uses.
File names are a known friction point. Apple's older HFS+ file system stored names in a decomposed form close to NFD, while many other systems use composed names, so the same visible name can fail to match across systems unless both sides normalize before comparing.
When to prefer plain or composed text
- Publishing, messaging or displaying text to people: keep the original or convert to NFC.
- Storing identifiers, keys or file names: choose one form, usually NFC, and normalize consistently on input and before comparison.
- Needing plain letters from styled Unicode "fonts" or ligatures: NFD will not help; NFKC or NFKD may, at the cost of losing distinctions, so review the result.
- Preparing accent-insensitive search: use NFD plus mark removal only for a separate matching key, never as a replacement for the source text.
Evidence gaps
This review relies on documented Unicode normalization behavior and the documented Java Normalizer API. It does not include measured performance figures, results from specific destinations, or screen-reader test results. If your decision depends on how a particular platform, database, search engine or assistive technology handles decomposed text, run a scoped test there with representative input, including combining marks and multi-code-point emoji.