No Login Data Private Local Save

CJK Text Line Break Tester - Online word‑break & line‑break

9
0
0
0

CJK Text Line‑Break Tester

Test how Chinese, Japanese & Korean text wraps with different CSS word-break, line-break & overflow-wrap values.

Presets:

这是一段中文文本,包含各种标点符号。「你好,世界!」这句话使用了中文引号。另外还有顿号、分号;以及冒号:等标点符号。通过调整line-break属性,可以观察标点符号在行首和行尾的不同表现。CJK文本换行测试:This is a mixed content example with English words and 中文汉字混合在一起。

Actual width: --px Drag slider or resize the dashed box to change width
.cjk-text {
  word-break: normal;
  line-break: auto;
  overflow-wrap: normal;
}
Understanding CJK Line Breaking

Unlike Latin-based languages where words are separated by spaces and line breaks occur primarily at word boundaries, CJK (Chinese, Japanese, Korean) text has no mandatory word separators. By default, browsers treat each CJK character as an independent unit that can serve as a line-break point. This means CJK text can wrap at almost any character boundary—a behavior governed by the line-break property. Chinese and Japanese typically lack spaces, while Korean uses spaces between words (similar to English), making word-break: keep-all particularly relevant for Korean content.

word-break: break-all forces the browser to break lines at any character—even inside non-CJK words like English terms or URLs. For CJK text, this is largely redundant since CJK characters already permit breaks between them. However, it significantly affects mixed-language content: long English words or URLs embedded in CJK paragraphs will be aggressively broken mid-word to prevent overflow. Use this when you need strict containment of content within narrow containers, but be aware it can make English text harder to read.

word-break: keep-all prevents line breaks within words and only allows breaks at spaces or other explicit separators. This is essential for Korean (which uses spaces between words) and also beneficial for Chinese/Japanese when you want to keep semantic units together. However, for Chinese and Japanese text without spaces, keep-all may cause text to overflow its container if no natural break points exist. Combine it with overflow-wrap: break-word as a safety net to handle overflow gracefully.

The line-break property specifically controls how CJK punctuation and symbols behave at line boundaries. It accepts five values: auto (browser default), loose (more permissive—allows more punctuation at line start/end), normal (balanced rules), strict (restrictive—prevents certain punctuation from appearing at line start), and anywhere (allows breaks around any punctuation). For example, in Japanese typography, it's traditionally considered poor form to start a line with a small kana or certain punctuation marks—line-break: strict enforces these rules.

Different browsers implement CJK line-breaking with subtle variations. Safari (WebKit) historically had stricter default line-breaking rules for CJK text, and support for newer CSS values like line-break: anywhere or overflow-wrap: anywhere arrived later than in Blink-based browsers (Chrome, Edge). To ensure cross-browser compatibility, always test with multiple browsers and consider using word-break: break-all or overflow-wrap: break-word as a fallback for overflow prevention. As of 2024, Safari 15.4+ supports most modern line-breaking properties.

For mixed CJK-Latin content, the best strategy is: (1) Use word-break: normal as the base to allow natural CJK wrapping. (2) Add overflow-wrap: break-word to handle long English words or URLs that might overflow narrow containers. (3) Consider hyphens: auto for Latin portions (with appropriate lang attribute). (4) Test at all breakpoints—what looks fine at 768px may overflow at 320px. (5) For Korean specifically, word-break: keep-all preserves word integrity while overflow-wrap: break-word provides overflow safety.

While both can break long words, they work differently: overflow-wrap: break-word is lazy—it only breaks a word if it would otherwise overflow the container. The browser first tries to wrap at natural break points, and only resorts to mid-word breaking as a last resort. word-break: break-all is aggressive—it allows breaking at any character regardless of overflow, which can create awkward mid-word breaks even when not strictly necessary. For most use cases, overflow-wrap: break-word provides a better reading experience while still preventing overflow.

Modern browsers handle CJK line-breaking efficiently for most use cases. However, very long passages (10,000+ characters) with line-break: strict may require slightly more computation as the browser evaluates each character against complex rule sets. For performance-critical applications: use line-break: auto (the default), avoid unnecessary nesting of elements with different line-breaking rules, and consider content-visibility: auto for off-screen content. In practice, line-breaking performance is rarely a bottleneck compared to layout, paint, or JavaScript execution.