Text Overflow and Wrapping
This page lists the CSS properties related to text overflow and wrapping (line-breaking).
CSS Properties
text-overflow
Sets how to clip text when it overflows the container. (Requires white-space: nowrap
and overflow: hidden
.)
Specify clip
or ellipsis
.
clip-clip-clip-clip-clip-clip-clip-clip-clip-clip
ellipsis-ellipsis-ellipsis-ellipsis-ellipsis-ellipsis
white-space
Determines how white spaces in the source code are handled. (White spaces are spaces, tabs, and newlines.)
normal
— (1) consecutive white spaces are collapsed into one; (2) newlines are treated the same as spaces and tabs; (3) lines are broken at<br>
and as necessary.nowrap
— (1) consecutive white spaces are collapsed into one; (2) no line breaks occur (everything is in one line)pre
— (1) white spaces are preserved as-is; (2) lines are broken only at newlines and at<br>
pre-wrap
— (1) white spaces are preserved; (2) lines are broken at newlines, at<br>
, and as necessary. ("Likepre
but allow wraps".)pre-line
— (1) white spaces are collapsed; (2) lines are broken at newlines, at<br>
, and as necessary. ("Likepre
but allow wraps, collapse all but newlines".)break-spaces
— Likepre-wrap
, but any sequence of preserved white space always takes up space, including at the end of the line (normally they do not take up space at the end of the line, i.e. they "hang"). Example of break-spaces.
word-break
Sets where line break appears wherever the text would otherwise overflow its container.
normal
— use the normal rule (never break out long words; Chinese/Japanese/Korean characters can be broken)break-all
— allows break anywherekeep-all
— never break out long words (even for Chinese/Japanese/Korean characters)
overflow-wrap
overflow-wrap
was originally named word-wrap
. It has since been renamed and aliased (MDN).Determines how to break a single word if it overflows its container even when placed on its own line.
normal
— normal behavior (i.e. lines are only broken at spaces between words)anywhere
— break the long word anywhere (without inserting hyphens); formin-content
width calculation, "soft wrap" opportunities introduced by the word break are consideredbreak-word
— break the long word anywhere (without inserting hyphens); formin-content
width calculation, "soft wrap" opportunities introduced by the word break are NOT considered
hyphens
Determines how to add hyphens when a long word is broken.
You can suggest word-break opportunities by using -
(hard hyphen characters, always rendered whether or not the word is broken there)
OR ­
(soft hyphens, only rendered if the word is broken there). (<wbr>
will never render hyphens.)
manual
— word can only break where suggested (default)none
— don't break or hyphenate words, even where suggested (lines will only wrap at whitespace characters)auto
— browsers can break wherever it sees fit (uses dictionary), but manually suggested breakpoints will override automatic breakpoints
References
- text-overflow (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow
- white-space (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
- CSS Property white-space example for break-spaces (Stack Overflow) — https://stackoverflow.com/questions/64699828/css-property-white-space-example-for-break-spaces
- overflow-wrap (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-wrap
- hyphens (MDN) — https://developer.mozilla.org/en-US/docs/Web/CSS/hyphens
- hyphens (CSS-Tricks) — https://css-tricks.com/almanac/properties/h/hyphenate/