Skip to content
Basics

Grapheme Clusters

Why one "user-perceived character" might be multiple code points.

Time Complexity
O(N)
Space Complexity
O(1)

Interactive Visualization

1 Grapheme Cluster (User View)
๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ
7 Hidden Code Points
๐Ÿ‘จ
U+1F468
ZWJ
U+200D
๐Ÿ‘ฉ
U+1F469
ZWJ
U+200D
๐Ÿ‘ง
U+1F467
ZWJ
U+200D
๐Ÿ‘ฆ
U+1F466

Technical Guide

Even code points don't always represent one visual character. A 'Grapheme Cluster' is what a user sees as a single character. For example, a family emoji is actually multiple emojis (Man, Woman, Girl, Boy) joined by invisible 'Zero Width Joiner' code points. Algorithms that reverse strings or delete characters must work at the Grapheme Cluster level to avoid corruption.

Logical Phases

  • 1
    Combining a base character with skin tone modifiers.
  • 2
    Joining independent characters with ZWJ (U+200D).
  • 3
    Applying accent marks (Combining Diacritical Marks) to base letters.
  • 4
    Parsing sequences to find logical visual boundaries.

Implementation

const cluster = 'nฬƒ'; // 'n' + accent
// length is 2, but it looks like 1.

Expert Pitfalls

Splitting a string in the middle of a cluster, leaving a 'floating' accent or modifier.