Wrapping, white space and overflow
Definition and purpose
White-space controls whitespace handling and wrapping. Overflow wrapping provides break opportunities for otherwise unbreakable words. Ellipsis signals clipped inline text.
Wrap long tokens
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>CSS practice</title><style>#a { width: 120px; overflow-wrap: anywhere; } #b { white-space: pre-wrap; }</style></head><body><p id="a">VeryLongUnbrokenIdentifierForTesting</p><pre id="b">A BC</pre></body></html>The long token can wrap and B preserves spaces.
Syntax and mental model
white-space: pre-wrap preserves spaces and line breaks while allowing wraps. overflow-wrap: anywhere can split a long token when needed. A single-line ellipsis usually needs constrained width, nowrap, hidden overflow and text-overflow: ellipsis.
Single-line summary
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } </style> </head> <body> <p id="a">A long chapter title for an article</p> <p>A long chapter title for an article</p> </body></html>The summary is clipped with an ellipsis; the full title remains below.
Common mistakes
Do not hide essential content behind an ellipsis with no way to reveal it. Prefer wrapping for prose; use a scrollable code area when line structure matters.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Alignment and decoration. Next lesson: Readable article mini-project.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Wrapping, white space and overflow — knowledge check
Five questions on wrapping, white space and overflow.
Which preserves spaces and permits wrapping?
Which enables emergency breaks?
Is text-overflow alone sufficient for ellipsis?
Which is preferable for essential prose?
What does nowrap prevent?