Grapheme Cluster Boundary
Rules (UAX#29) for determining where one user-perceived character ends and another begins. Critical for cursor movement, text selection, and correctly counting 'characters' in UI.
What is Grapheme Cluster Boundary (Grapheme Break)?
A grapheme cluster boundary is a position in a Unicode text string where one user-perceived character ends and the next begins. The rules that determine these positions are defined in Unicode Standard Annex #29 (UAX#29), titled Unicode Text Segmentation. The concept matters wherever software needs to move a text cursor, measure string length in visible characters, or break text at line wraps.
The term grapheme cluster distinguishes between code points (the atomic integer values Unicode assigns to each character) and the actual glyphs a user perceives. A single user-perceived character such as the letter é may be encoded as one code point (U+00E9, precomposed) or as two code points — e (U+0065) followed by the combining acute accent (U+0301). Both representations should be treated as a single grapheme cluster with a single boundary on each side.
Extended vs Legacy Grapheme Clusters
UAX#29 defines two types of grapheme clusters:
- Legacy grapheme clusters — a simpler, older definition that always breaks before a spacing combining mark. This can produce incorrect results for some scripts.
- Extended grapheme clusters — the modern, recommended definition. It handles Hangul syllable sequences, emoji modifier sequences, emoji ZWJ sequences, and regional indicator pairs correctly.
Almost all modern implementations use extended grapheme clusters. The distinction matters when you need to precisely count how many "characters" a user sees.
Boundary Rules by Script
Hangul syllables are a classic example where grapheme break rules are non-trivial. A Korean syllable like 각 is composed of a leading jamo (ᄀ, U+1100), a vowel jamo (ᅡ, U+1161), and a trailing jamo (ᆨ, U+11A8). UAX#29 defines specific rules so that these three code points form a single grapheme cluster.
Emoji sequences add further complexity. The flag emoji for France 🇫🇷 is encoded as two Regional Indicator Symbol Letters — F (U+1F1EB) and R (U+1F1F7). UAX#29 keeps these paired as one cluster. Similarly, 👨👩👧 is a family ZWJ sequence of five code points joined by Zero Width Joiner (U+200D), forming one cluster.
Combining marks in scripts like Devanagari, Arabic, and Thai can stack multiple diacritics onto a base character. All combining marks that follow a base code point without an intervening boundary are included in the same grapheme cluster.
Cursor Movement Implications
When a user presses the arrow key in a text editor, the cursor should move by one grapheme cluster, not one code point. Moving by code points would leave the cursor stranded inside a multi-code-point grapheme, causing partial deletions and display artifacts. Platforms implement this via ICU's BreakIterator, Swift's String.Index, or Rust's unicode-segmentation crate.
# Python: count grapheme clusters (requires third-party library)
import grapheme
text = "\u0065\u0301" # e + combining acute accent
len(text) # 2 code points
grapheme.length(text) # 1 grapheme cluster
Quick Facts
| Property | Value |
|---|---|
| Defining standard | Unicode Standard Annex #29 (UAX#29) |
| Two cluster types | Legacy grapheme clusters, Extended grapheme clusters |
| Recommended type | Extended grapheme clusters |
| Complex scripts | Hangul (jamo sequences), Indic (virama clusters) |
| Emoji cases | Regional indicators, ZWJ sequences, modifier sequences |
| Key use cases | Cursor movement, string length, line breaking |
| Implementation | ICU BreakIterator, Intl.Segmenter (JS), unicode-segmentation (Rust) |
Related Terms
More in Algorithms
Mapping characters to a common case form for case-insensitive comparison. More comprehensive …
Characters excluded from canonical composition (NFC) to prevent non-starter decomposition and ensure …
Normalization Form C: decompose then recompose canonically, producing the shortest form. Recommended …
Normalization Form D: fully decompose without recomposing. Used by the macOS HFS+ …
Normalization Form KC: compatibility decomposition then canonical composition. Merges visually similar characters …
Normalization Form KD: compatibility decomposition without recomposing. The most aggressive normalization, losing …
The position between sentences per Unicode rules. More complex than splitting on …
Comparing Unicode strings requires normalization (NFC/NFD) and optionally collation (locale-aware sorting). Binary …
Algorithm determining display order of characters in mixed-direction text (e.g., English + …
Standard algorithm for comparing and sorting Unicode strings using multi-level comparison: base …