Combining Characters and Diacritics in Unicode

· 2 min read

Combining characters are Unicode code points that attach to the preceding base character to form a composite glyph. Diacritical marks—accents, umlauts, tildes, cedillas—are the most familiar examples. Understanding combining characters is essential for correct string comparison, text rendering, and input validation in multilingual applications.

How Combining Characters Work

A combining character has the General Category M (Mark) and is rendered at the position of the preceding base character. U+0301 COMBINING ACUTE ACCENT placed after e (U+0065) produces é—visually identical to the precomposed U+00E9 LATIN SMALL LETTER E WITH ACUTE. Multiple combining marks can be stacked—for example, a base character can carry both a macron and a dot below.

The Combining Diacritical Marks Block

The Combining Diacritical Marks block (U+0300–U+036F) contains 112 combining marks used with Latin, Greek, and Cyrillic scripts. Additional combining marks for other scripts are scattered through blocks dedicated to those scripts—combining marks for Arabic are in the Arabic block, for Devanagari in the Devanagari block, and so on.

Zalgo Text and Stacking Limits

Unicode places no hard limit on the number of combining marks that can follow a single base character. This enables the infamous Zalgo text—extremely tall stacked-diacritic text that overflows line boundaries. Z̶̡̢͕͙̹̳̙͇̯̱̣̜͙͕͋̈̂̉̎͑͂̄̂̕a̸̫͕̱̲͊͌l̷̲̺̳͔̼̙̜͇̭͑̒̍̊͐̊̿̚g̵̛̝͕̲̗͒͑̉̐̑̄̕͠o̸̱̝̾̍̌̾̌͐̈̐͝ text is created by programmatically appending hundreds of combining marks to each base character. In production systems, sanitise input by limiting the number of consecutive combining marks allowed per base character.

Sorting with Combining Characters

The Unicode Collation Algorithm (UCA) defines how strings containing combining characters should be sorted. Naive byte-order sorting produces incorrect results for many scripts. For example, Swedish sorts å after z, while many systems default to treating it as a variant of a. Use an ICU-based collation library for correct multilingual sorting. The normalisation article covers the closely related topic of canonical decomposition.