{
  "id": "grapheme-cluster",
  "title": "Grapheme Cluster",
  "lang": "en",
  "source_lang": "en",
  "summary": "A grapheme cluster is a sequence of Unicode code points treated as a single unit for text segmentation, approximating a user-perceived character.",
  "category": "computer-science",
  "subcategory": "software",
  "type": "concept",
  "aliases": [
    "Unicode grapheme cluster"
  ],
  "generated_at": "2026-11-05",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/grapheme-cluster/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/grapheme-cluster/",
      "json": "https://aiwiki.page/zh/grapheme-cluster.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A grapheme cluster is a sequence of one or more Unicode code points grouped together by text-segmentation rules as an approximation of a user-perceived character. A letter followed by a combining accent, for example, generally forms one grapheme cluster even though it contains two code points. Grapheme clusters provide useful boundaries for cursor movement, text selection, character counting, and truncation. They are not necessarily equivalent to linguistic characters, displayed symbols, or units of storage."
    },
    {
      "heading": "Characters, code points, and glyphs",
      "text": "The word character can refer to several different units. Grapheme clusters help distinguish user-facing text units from their underlying representation.\n\n- A code point is a numerical position in a character set. Unicode assigns code points to letters, combining marks, punctuation, control characters, and other elements.\n- A code unit is a basic unit of a particular character encoding. UTF-8 uses 8-bit code units, while UTF-16 uses 16-bit code units. One code point may require several code units.\n- A grapheme is a unit of a writing system, defined through linguistic analysis. Its relationship to Unicode segmentation is not always one-to-one.\n- A glyph is a visual form produced when text is rendered. One grapheme cluster can require multiple glyphs, while a single ligature glyph can represent several grapheme clusters.\n\nConsequently, counting bytes, code units, code points, glyphs, and grapheme clusters can produce different answers for the same text.\n\nFor example, the letter “é” can be represented either by the single code point U+00E9, LATIN SMALL LETTER E WITH ACUTE, or by U+0065, LATIN SMALL LETTER E, followed by U+0301, COMBINING ACUTE ACCENT. Both representations normally constitute one grapheme cluster."
    },
    {
      "heading": "Unicode segmentation",
      "text": "Unicode Standard Annex #29, Unicode Text Segmentation, defines default rules for locating grapheme-cluster boundaries. The rules operate on code points and their Unicode properties, rather than on the appearance of rendered text.\n\nThe extended grapheme cluster is the principal default unit used for general-purpose text processing. Unicode also defines legacy grapheme clusters, an older, more limited form retained for compatibility. Extended rules handle additional cases, including certain spacing marks and script-specific sequences.\n\nThe rules are ordered: an earlier rule can determine a boundary before a later rule is considered. Important effects include:\n\n- A base character and following combining characters generally remain together.\n- A carriage return followed by a line feed forms one cluster, although most other control-character boundaries cause breaks.\n- Certain sequences of Hangul consonant and vowel components remain together.\n- Defined emoji sequences, including modifier sequences and some sequences joined by a zero-width joiner, remain together.\n- Consecutive regional-indicator symbols are grouped in pairs, supporting flag sequences.\n- Certain Indic consonant-linker sequences remain together under the extended rules.\n\nThis is therefore not simply an algorithm that attaches all marks to the preceding letter. It uses several classes of characters and, in some cases, contextual information.\n\nA cluster also need not have a conventional base character: a combining mark at the start of text still belongs to a cluster. Conversely, not every cluster is visible. The carriage-return–line-feed pair is a particularly clear example of why “one visible symbol” is only an approximation.\n\nDefault rules and tailoring\n\nDefault segmentation provides a common baseline, not a complete model of every writing system or editing convention. Implementations can use documented tailoring for particular languages or environments.\n\nThe Unicode version matters as well. Character properties and segmentation rules evolve, so implementations using different Unicode data can disagree about boundaries. Reproducible processing may therefore require specifying both the segmentation method and its Unicode version."
    },
    {
      "heading": "Examples",
      "text": "Under default extended grapheme-cluster rules, the following sequences each form one cluster:\n\nText or sequence | Code points | UTF-16 code units | Extended grapheme clusters\na | 1 | 1 | 1\né, encoded as U+00E9 | 1 | 1 | 1\ne followed by U+0301 | 2 | 2 | 1\n👍🏽 | 2 | 4 | 1\n🇯🇵 | 2 | 4 | 1\n👨‍👩‍👧‍👦 | 7 | 11 | 1\n\nThe family sequence contains four pictographic code points and three zero-width joiners. Its treatment as one cluster does not guarantee that a font or rendering system will display it as one unified picture.\n\nLikewise, the letters f and i ordinarily form two grapheme clusters even if a font displays them using an fi ligature. Grapheme segmentation is independent of that typographic substitution."
    },
    {
      "heading": "Relationship to normalization",
      "text": "Unicode normalization and grapheme segmentation solve different problems.\n\nNormalization transforms text into defined forms, including NFC, which favors canonical composition where possible, and NFD, which uses canonical decomposition. Segmentation identifies boundaries without necessarily changing the text.\n\nFor the two representations of “é,” normalization can make the code-point sequences identical. Grapheme segmentation already treats each representation as one cluster. It does not, however, make them equal in an ordinary code-point comparison.\n\nUnicode’s default grapheme-boundary rules are designed to preserve corresponding boundaries under canonical equivalence. This does not mean that all visually similar strings are equivalent, nor that compatibility normalization preserves grapheme-cluster counts. For example, compatibility normalization can expand a single encoded typographic ligature into multiple ordinary letters."
    },
    {
      "heading": "Applications",
      "text": "Editing and text selection\n\nText editors commonly use grapheme boundaries to avoid placing a cursor between a base letter and its accent or inside an emoji sequence. Selection and replacement operations can use the same boundaries.\n\nActual editing behavior may be more specialized. A backspace operation can remove a whole cluster, a single combining mark, or another script-appropriate component, depending on the application. Grapheme clusters supply useful default boundaries rather than a universal specification for every editing command.\n\nCounting and truncation\n\nA user-facing character limit often uses extended grapheme clusters because byte or code-point counts can penalize combining sequences and multi-code-point emoji.\n\nTruncating at a cluster boundary avoids cutting inside such sequences. It does not guarantee a particular visual width: clusters can occupy different amounts of space, and some occupy no visible space. Terminal columns, rendered line lengths, and grapheme counts are separate measurements.\n\nProgramming interfaces\n\nSome programming languages and text libraries expose grapheme-segmentation facilities. In JavaScript, Intl.Segmenter supports grapheme segmentation:\n\nconst text = \"e\\u0301\";\nconst segmenter = new Intl.Segmenter(\"en\", {\n  granularity: \"grapheme\"\n});\n\ntext.length;                       // 2 UTF-16 code units\nArray.from(text).length;            // 2 code points\nArray.from(segmenter.segment(text)).length; // 1 grapheme cluster\n\nA segmentation API may report offsets in the language’s native string-indexing units. JavaScript offsets, for example, remain UTF-16 code-unit offsets; identifying one cluster does not change how the string is stored or indexed.\n\nSome regular expression engines also support \\X for matching an extended grapheme cluster. Support and Unicode-version behavior depend on the engine."
    },
    {
      "heading": "Limits and implementation considerations",
      "text": "Grapheme clusters are not a universal definition of “character.” They do not necessarily correspond to orthographic syllables, phonemes, words, or individual rendered objects. Word segmentation, line breaking, and natural-language tokenization require different rules.\n\nCluster boundaries can also depend on surrounding text. Regional-indicator pairing depends on the preceding run, while some emoji and script-specific rules require additional context. Segmenting separately supplied chunks without carrying boundary state can therefore differ from segmenting their concatenation.\n\nThere is no small fixed upper bound on cluster length: a base character may be followed by a long sequence of combining marks. A limit expressed only in grapheme clusters consequently does not impose a reliable limit on storage size or rendering cost. Resource accounting must distinguish cluster counts from code-point, code-unit, and byte counts.\n\nFinally, grapheme segmentation does not establish visual identity or prevent deceptive text. Different clusters can look alike, and a single cluster can render differently across fonts and platforms. Segmentation, normalization, rendering, and security-sensitive text comparison remain distinct operations."
    }
  ],
  "links": [
    "unicode",
    "code-point",
    "character-encoding",
    "utf-eight",
    "utf-sixteen",
    "grapheme",
    "glyph",
    "byte",
    "combining-mark",
    "algorithm",
    "programming-language",
    "javascript",
    "application-programming-interface",
    "tokenization"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}