Why Thai Text on the Web or E-Readers Splits Characters Wrong
en•July 16, 2026•Updated: October 5, 2026•18 min read

Why Thai Text on the Web or E-Readers Splits Characters Wrong

Web DevelopmentThai LanguageTypographyCSSAstroDebugging

อ่านบทความนี้เป็นภาษาไทย: ทำไมตัวอักษรไทยบนเว็บหรือ e-reader ถึงตัดอักษรผิด

The first post on this blog was written in Thai, until someone messaged me that “reading on mobile, the text is broken.” That’s how I found out my own site had a Thai word-breaking problem I’d never noticed before. This post is a record of the whole fix: from where I got it wrong at first, to the real answer, and what I learned along the way turned out to be a much bigger deal than I expected. Including the fact that multiple Thai word tokenizers don’t even agree with each other on what a “word” is, all the way to how other languages using an Abugida (a script where each consonant carries its own attached vowel) combined with Scriptio Continua (a writing system with no spaces between words), such as Lao, Khmer, Burmese, and Tibetan, solve this same problem.


The symptom: a character that “goes missing” mid-word

A reader sent two screenshots: one from the LINE in-app browser on a phone, one exported as a PDF from mobile Safari. Both showed the opening paragraph of an article, and the word “เตรียม” (prepare) was split mid-word, leaving a single stranded character “เ” at the end of one line, with the rest, “ตรียม”, wrapping to the next.

The bug report

Both screenshots came from a phone, not a simulation. And critically: opening the same page in Chrome on my own laptop showed no problem at all. The text wrapped perfectly normally.

That gap, same page, same content, completely different rendering across machines, is where the whole investigation started.

Wrong hypothesis #1

“WebKit doesn’t support Thai word segmentation”

The tempting first explanation: the Safari/WebKit environment behind the reported screenshots must lack Thai word segmentation, unlike Chrome. That was a hypothesis about the browser implementation, not something established by the screenshots alone.

That hypothesis did not fit my test. I loaded BBC Thai in Playwright’s WebKit and found the tested Thai paragraphs wrapped normally. Playwright’s WebKit is useful for comparison, but it is not the exact iOS Safari or LINE browser build that produced the screenshots.

So I ran a controlled test: one blank HTML page, the same Thai paragraph repeated five times, each copy with a different word-break/overflow-wrap combination, all rendered by the same WebKit engine side by side:

CSS used Result in the original WebKit test
No override at all (browser default) Wraps correctly
overflow-wrap: break-word alone Wraps correctly
word-break: break-word (legacy) Wraps correctly
word-break: normal; overflow-wrap: normal; Wraps correctly
word-break: keep-all + overflow-wrap: break-word (what my site had at the time) Breaks mid-word

The real cause

It’s a bug I shipped myself.

The site’s own CSS had a comment reading /* Thai typography adjustments for spacing and word-breaking */, meaning this was a past attempt to fix Thai typography that had actually made things worse than the browser’s own default.

/* before */
.markdown-body[lang="th"] {
  line-height: 1.8;
  word-break: keep-all;
  overflow-wrap: break-word;
}

The original test isolated word-break: keep-all together with overflow-wrap: break-word as the combination associated with the bad wraps. Removing keep-all fixed that case. However, the CSS Text specification preserves dictionary-based breaking under keep-all; it does not define this property as disabling Thai segmentation. The observed result should therefore be described as an implementation-specific interaction in the tested environment, not the intended behaviour of CSS. The screenshots alone do not prove which internal lookup failed. overflow-wrap: break-word can introduce emergency breaks when an otherwise unbreakable run would overflow, which is consistent with the symptoms.

A real example from another post on this site, before the fix. Thai text is broken mid-word at several points in the same paragraph. A real example from another post on this site, before the fix.

Another example from the opening paragraph of the same post. Thai words are broken mid-word starting from the very first line. The opening paragraph of the same post. Words break mid-word starting from the first line.

The fix is one deleted line:

  .markdown-body[lang="th"] {
    line-height: 1.8;
-   word-break: keep-all;
    overflow-wrap: break-word;
  }

In the original Playwright WebKit retest, the word that used to split (เตรียม → เ + ตรียม) stayed together, and the tested Chrome case still wrapped normally. This is evidence for the workaround in those test cases, rather than a guarantee for every browser version, font or viewport.

What remained: candidate boundaries to check in actual layout

Fixing the CSS addressed the reported case. In the original analysis of a 35,436-character scholarship/visa article, my notes recorded 70 candidate words among 934 distinct tokens whose boundaries differed from Intl.Segmenter results. These are historical results for that input and environment, not a count of verified rendering defects. Examples included:

  • ตัวเอง (oneself), an extremely common pronoun, split into ตัว + เอง
  • ขั้นตอน (process/step), used in nearly every section, split into ขั้น + ตอน
  • เจ้าหน้าที่, สถานทูต, พาสปอร์ต, ต้นสังกัด, เร่งด่วน, ใบเสร็จ, สถานกงสุล, words that appeared repeatedly in that input. The initial notes recorded 253 candidate occurrences across the audit; that is not a current count for this typography article.

That made me change the question from “does removing the CSS rule fix the reported case?” to “which remaining boundaries would look undesirable in actual layout?” Intl.Segmenter with word granularity reports word segments, not rendered line breaks. ICU distinguishes word and line boundary iterators, and implementations and data versions can differ. Tokenizer disagreement is useful for finding candidates, but each candidate still needs checking in the browser at relevant widths.

Shopping for “ground truth” from Thai word tokenizers

The original plan was to compare another tokenizer against Intl.Segmenter and treat it as “ground truth.” That framing was too strong: another tokenizer supplies a second segmentation policy, not an authority on visually appropriate line breaks.

The table times how long each tokenizer takes to split the same text: a 47,003-character (code point) extract of the scholarship article, on an Apple M3 Max on October 5, 2026. Each time is the median of 30 runs after warm-up, excluding loading. Compare times within the same runtime: a browser, Node.js and Python are different environments. The 35,436-character analysis earlier in the article used different text.

Tokenizer Runs in Type Time (ms)
Intl.Segmenter Browser (Chromium 149) Built-in 2.40
Intl.Segmenter Node.js 25 Built-in 3.10
NewMM TypeScript, safe mode Node.js 25 Dictionary 11.72
NewMM TypeScript Node.js 25 Dictionary 12.87
wordcut Node.js 25 Dictionary 85.83
PyThaiNLP newmm-safe Python 3.14 Dictionary 42.06
PyThaiNLP newmm (default) Python 3.14 Dictionary 55.32
PyThaiNLP attacut Python 3.12 Neural model 274.53
PyThaiNLP deepcut Python 3.12 Neural model 2,079.91

Why Intl.Segmenter appears twice: it is the same built-in API, timed once in the browser and once in Node.js. The two did not even split the text the same way: Chromium produced 14,707 pieces, Node.js 14,649.

One logarithmic dot plot compares all nine tokenizer/runtime results, sorted by warm median time. Filled circles show medians and hollow diamonds show p95. Runtime labels distinguish Node, Python CPU and Chromium. Each major axis step is a tenfold increase; medians are in the preceding table. One logarithmic dot plot compares all nine tokenizer/runtime results, sorted by warm median time. Filled circles show medians and hollow diamonds show p95. Runtime labels distinguish Node, Python CPU and Chromium. Each major axis step is a tenfold increase; medians are in the preceding table.
All nine results share one logarithmic time axis, sorted by median. Filled circles show the warm median; hollow diamonds show p95. Each major step is 10×; farther left is faster. Runtime labels identify the different environments. Timing is not line-breaking quality; medians are in the table above.
Benchmark setup and raw measurements

Engine notes:

  • NewMM TypeScript (nlpo3-newmm-typescript 1.1.0) adapts nlpO3’s NewMM. In a browser it needs its dictionary (~314KB gzip in the original investigation) fetched separately and loaded with fromWordList(). Safe mode chunks long input.
  • wordcut 0.9.1 is dictionary-based (~105KB gzip in the original investigation); browsers need its fs/glob dictionary loading adapted.
  • PyThaiNLP newmm is dictionary-based maximum matching with Thai Character Cluster constraints and is PyThaiNLP’s default; newmm-safe avoids long processing on ambiguous input.
  • AttaCut used its default attacut-sc model on PyTorch; DeepCut used its bundled CNN weights on TensorFlow. Browser ports were not tested.
  • p95 times are in the chart and the raw report.

All engines received the identical string, including whitespace: 47,003 Unicode code points / 123,848 UTF-8 bytes on an Apple M3 Max (macOS, arm64). Each engine had five warm-up calls and 30 timed calls; p95 uses nearest rank. The original run used Node 25.8.2 / ICU 78.3, Python 3.14.3, TypeScript NewMM 1.1.0, wordcut 0.9.1 and PyThaiNLP 5.3.8.

The added neural run used PyThaiNLP 5.3.8 in Python 3.12.13, AttaCut 1.0.6 (attacut-sc, PyTorch 2.14.1, default 12 intra-op threads), and DeepCut 0.7.0.0 (bundled cnn_without_ne_ab.h5, TensorFlow 2.16.2, tf-keras 2.16.0 in legacy Keras mode). Both ran on CPU, with models preloaded before the first segmentation; framework defaults and DeepCut’s default prediction batches/verbosity were retained. These settings are part of the measurement, not universal engine performance.

The browser run used headless Chromium 149.0.7827.55, locale th, word granularity for native Intl.Segmenter, in a fresh browser context. The raw report also contains an ICU/WASM build timed in the same run; it is left out of this article.

Added engine / runtime Import or browser setup (ms) Model loading (ms) First segmentation (ms)
AttaCut / Python CPU 7,111.40 9.59 305.09
DeepCut / Python CPU 26,477.13 136.64 5,876.25
Native Intl.Segmenter / Chromium 5.70 — 6.50

These startup values are single observations, affected by OS/library/browser caches, not cold-start averages. Warm timings include segmentation and materializing complete output lists, excluding installation, downloads, process startup, extraction and rendering. The raw report retains every sample, token counts, input SHA-256, configurations and separate setup/first-call observations. Runners: scripts/benchmark-thai-segmentation.mjs, scripts/benchmark-thai-neural.py and scripts/benchmark-thai-browser.mjs; optional frameworks and Playwright are installed outside the site’s dependencies.

Faster does not mean better line breaking. These are timings on one desktop computer, not a phone, and they measure splitting text into words, not where lines actually break. The neural and dictionary engines also ran on different Python versions and frameworks, so the gap is not purely the algorithm.

PyThaiNLP is not exclusively a deep-learning tokenizer. Its documentation lists dictionary-based engines including newmm (the default), longest and mm, as well as neural engines. newmm-safe adds a mechanism to avoid long processing on continuously ambiguous input. Choosing attacut or deepcut is an engine choice, not a requirement for using PyThaiNLP.

The original wordcut workflow produced problematic output around “สหรัฐฯ”. Without a retained minimal reproduction that separates text extraction from tokenization, I should not attribute that result to a universal wordcut bug. The installed TypeScript package’s README mentions AI-assisted development; that statement alone does not establish the quality or provenance of every line of code. A practical assessment should consider tests, maintenance, edge cases and behaviour on the intended input.

Along the way

The original local wordcut measurements recorded ~88ms for initialization, with ~71ms attributed to CPU work, plus ~61–76ms for segmentation. Those figures describe that machine and input. Pre-bundling data can avoid a download, but it does not remove parsing or trie-construction work. The earlier 300–500ms phone estimate was an extrapolation, not a measurement on a phone; real device profiling is needed before claiming a perceptible main-thread delay.

The twist nobody expected: swap the ground truth, get a 6x different answer

I re-ran the mismatch analysis using nlpo3-newmm-typescript as ground truth instead of wordcut, expecting similar or better results. The original comparison recorded 431 candidate mismatches instead of 70, roughly 6x more. Those counts describe the original input and tokenizer versions, not independently verified line-breaking errors.

Looking at the actual list explains why: words like เพื่อให้ (“in order to”), ไม่ต้อง (“don’t need to”), and อยู่แล้ว (“already”) were registered as single tokens by this tokenizer’s dictionary, but they’re just two ordinary words placed next to each other, the same way an English reader wouldn’t blink if “in order to” wrapped mid-phrase across a line. This isn’t the same class of problem as “ตัวเอง” splitting, which looks genuinely wrong because it’s a tightly bound unit readers process as one piece.

The most important finding in this whole post

Different Thai tokenizers do not always agree on what to treat as a token. Dictionaries, algorithms and context handling can group compounds and common phrases differently. A disagreement is not automatically an error, and an NLP token is not necessarily the unit that should remain together on a line. For this project, manual review and rendered examples are more useful than treating any one tokenizer as infallible ground truth.

So what do actual e-readers do about this?

I also looked at e-reader reports. These sources show limitations in particular implementations; they do not establish that every e-reader has the same problem or that nobody has solved Thai layout well.

KOReader: issue #11701, opened in 2024, reports inadequate Southeast Asian line breaking with libunibreak. It is closed as “not planned”, not open. The reporter proposed ICU4C, libthai, preprocessing with zero-width spaces, and extending libunibreak. The issue description mentions size and build complexity as possible trade-offs, but it is not evidence that the maintainers evaluated every option or closed the issue specifically because of executable size. This is a related line-breaking limitation, not proof of the same CSS-triggered WebKit bug.

Kindle: I encountered user reports about displaced or missing Thai marks. Without a reproducible file, device/firmware version and a primary technical diagnosis, those reports should not be generalized to current Kindle firmware or used to rank it against KOReader.

Maiyamok (ๆ): the W3C Thai Gap Analysis reports a test in which Gecko, Blink and WebKit let the repetition mark begin a line, including when a space precedes it. The expected convention keeps it with the preceding text. That is a documented test result, not a fresh test of every currently released browser version.

What about other languages that write without spaces too?

Widening the search: Thai isn’t the only script written without spaces between words (scriptio continua), and, this was the most interesting part, not every such script has the same problem.

Lao, Khmer and Burmese also require language-specific segmentation and layout handling. That does not mean their rules or implementation failures are identical to Thai’s. W3C’s discussions for Khmer and Lao ask about word versus syllable boundaries and seek evidence of rendering problems. These discussions show questions being investigated, rather than proving that line breaking for all these scripts is entirely unspecified.

Burmese also has a separate encoding-compatibility issue: legacy Zawgyi text and Unicode Myanmar text are not interchangeable. Changing fonts alone is not a reliable conversion. This concerns encoding and shaping, and should be distinguished from choosing line-break opportunities.

Tibetan uses explicit syllable separators. The tsheg (་, U+0F0B) supplies common line-break opportunities without requiring a Thai-style word dictionary at each boundary. But it does not mark every legal break unconditionally. W3C’s Tibetan layout requirements describe exceptions, including the NGA–tsheg–shad sequence, and note a preference to keep some multisyllabic words together. U+0F0C is a non-breaking tsheg used in particular contexts. The useful comparison is that explicit separators simplify part of the task; they do not eliminate all layout rules.

Chinese and Japanese usually permit line breaks between characters, with restrictions around punctuation, small kana and certain character sequences. Japanese kinsoku rules, described in W3C’s Japanese layout requirements, govern many of these restrictions. Individual characters do not all represent complete independent words, and not every inter-character boundary is acceptable. The comparison with Thai concerns how break opportunities are determined, rather than one writing system being completely “solved.”

What this site actually ships now

  1. The Thai word-break: keep-all override was removed. This addressed the original tested case without adding a tokenizer to the article text. It does not guarantee perfect wrapping of all Thai text.
  2. A hand-reviewed list currently contains 71 entries, stored in src/data/thai-word-joins.json. It contains units chosen for this project’s demonstration of keeping text together; it is not a universal inventory of browser bugs. The demo uses the list, but the site’s article text is not postprocessed with it.
  3. An optional postbuild script exists: scripts/apply-thai-word-joins.mjs wraps listed matches in white-space:nowrap spans within built .markdown-body[lang="th"] content, skipping code, links, headings and other excluded elements. It is not part of npm run build. Match counts depend on the current article and list; the earlier 253 figure should not be presented as a current result for this article. The script also joins an immediately preceding grapheme to ๆ; this does not fully implement the spaced-maiyamok rule when that grapheme is a space.
  4. The demo loads external tokenizer assets only when their tabs are selected. The first three modes and native Intl.Segmenter need no full dictionary download. NewMM and wordcut load their own assets on demand. Being in devDependencies does not prevent a browser import from being bundled and delivered to readers.
  5. npm run thai:audit is a development tool for finding candidates. It compares the TypeScript tokenizer with Intl.Segmenter on built Thai posts, without automatically changing the list. Its output needs manual review and rendered checks; candidate counts change with the input and software versions.

The curated mode uses CSS no-wrap spans, not inserted U+2060 WORD JOINER characters. It is a demonstration, not an extra correction already applied to the surrounding article. We also chose not to apply a full tokenizer or automatic justification to all article text without evidence that it would improve reading.

Try it yourself

Type your own text or try the longer, three-paragraph Thai sample. It starts with embassy paperwork, then adds a fictional university application and a reading comparison with English words, dates, currency, decimals, abbreviations and repetition marks. These cases make it easier to inspect different boundary policies across a realistic amount of text.

The first three tabs show a break-all simulation, browser-default wrapping and curated no-wrap spans. The simulation is not an exact replay of the original WebKit behaviour. The remaining tabs apply live word segmentation from your browser’s Intl.Segmenter, TypeScript NewMM (normal or safe mode) and a browser adaptation of wordcut 0.9.1. Each token is displayed in a no-wrap span for comparison; that is not the tokenizer’s line-breaking algorithm. Browser-default wrapping is a separate mode.

NewMM and wordcut fetch their dictionaries only when selected. Every tokenizer reports one line in the same order: how many pieces it found, how long it took, and in how many places it splits the text differently from your browser’s Intl.Segmenter. Those places are highlighted in the output, and the list below the line shows each different split side by side. A difference is not a quality score, and a match is a normal result. Word-break markers are off by default because they add spacing; turn them on to see each piece. All text is processed locally in your browser. Python PyThaiNLP engines remain in the benchmark table; this static demo does not run them.

Loading and preparing the comparison…


References

Comments

Loading comments…

    Leave a comment

    Comments appear right away. Please be kind, and leave out personal or patient information.