🧩 CSS Tutorial: word-break

πŸ“Œ Introduction

The word-break property in CSS controls how words should break when they reach the end of a line. It is especially useful for handling long words, URLs, user-generated text, or multilingual content that doesn't naturally break. Properly using word-break keeps your layouts clean and prevents text overflow issues. ✨

🎯 Why Use word-break?

  • To prevent long words from breaking UI layouts 🧱
  • To handle long URLs or code snippets πŸ”—
  • To improve readability in narrow containers πŸ“±
  • To support languages without spaces (Chinese, Japanese, Korean) 🌏

✨ Syntax

Basic Syntax

selector {
  word-break: normal | break-all | keep-all | break-word;
}

Note

Note: break-word is a legacy value (alias for overflow-wrap: break-word) and is not part of the official spec, but still widely supported.

🧩 Available Values

1. normal (default)

Uses default line-breaking rules. Long words may overflow if they cannot break naturally.

2. break-all πŸ”¨

Breaks words at arbitrary points if necessary. Good for handling extremely long words or strings without spaces.

break-all Example

.break-all {
  word-break: break-all;
}

3. keep-all πŸ“

Prevents word breaks in languages using normal spacing (like Chinese, Japanese, Korean). Does not apply to languages using Latin script (English).

keep-all Example

.keep-all {
  word-break: keep-all;
}

4. break-word (legacy but useful) πŸ“

Breaks words only when absolutely necessary. Works as a fallback for older browsers. Equivalent to overflow-wrap: break-word.

break-word Example

.break-word {
  word-break: break-word; /* legacy */
}

πŸ”₯ Practical Examples

1. Prevent Layout Breaking Due to Long URLs

URL Example

.url {
  width: 200px;
  border: 1px solid #ccc;
  word-break: break-all;
}

2. Maintain Clean Text in Articles (Use Normal)

Normal Article Text

article p {
  word-break: normal;
}

3. Handling Multilingual CJK Content

keep-all Example

.cjk {
  word-break: keep-all;
}

4. Prevent Overflow in Narrow UI Boxes

Narrow Box

.narrow {
  width: 120px;
  word-break: break-word;
}

πŸ“Š Comparison Table

ValueBreak Long Words?Good For
normalNoStandard paragraphs
break-allYes (anywhere)Long URLs, technical content
keep-allNo for CJK languagesChinese/Japanese/Korean text
break-wordYes (when needed)General overflow handling

πŸ–ΌοΈ Visual Example

>>β€œTypography isn’t just about fonts β€” it’s about how text behaves under pressure.” ✨

πŸŽ‰ Conclusion

The word-break property is essential when dealing with long words, responsive layouts, and multilingual content. Use break-all for forcing breaks, keep-all for CJK text, and normal for typical content. Pair it with overflow-wrap and white-space for complete control over text layout! πŸš€