CSS text wrapping, truncation, and alignment
Quick reference for CSS text-align, wrapping, overflow-wrap versus word-break, and the conditions required for text-overflow.
text-overflow is not just ellipsis
The initial text-overflow is clip, which cuts overflowing inline content without a hint character. ellipsis can insert a visual cue, and some engines support a two-value form for the start and end of the line. Those extra values are a compatibility limit and were not tested here.
For a typical single-line ellipsis you need all of the following: a definite inline size (width or max-width, or a flex/grid item that can overflow), overflow other than visible (usually hidden or clip), and no wrapping (usually white-space: nowrap). Scrollable overflow (auto or scroll) can also clip visually, but it changes interaction. Multi-line clamping is often done with a non-standard -webkit-line-clamp pattern and is not a substitute for the standard single-line conditions.
| Syntax or property | Initial / default | Inherited | Applies to | Notes |
|---|
text-overflow | clip | no | block containers | Common values: clip, ellipsis. It only affects overflow in the inline direction and only when the box actually overflows. It is not inherited, and it does not by itself create a width, hide overflow, or disable wrapping. |
Ellipsis needs overflow, nowrap, and a width
text-overflow: ellipsis; /* not enough */
overflow: hidden;
white-space: nowrap;
max-width: 12rem;
A rule that only sets text-overflow: ellipsis is incomplete. The truncated line also needs a constrained inline size, hidden or clipped overflow, and nowrap.
- The first rule is the insufficient declaration. The second rule gathers the usual conditions. Painting of the ellipsis was not checked in a browser.
<p class="hint-only">docs/garden/week-01/planting-notes</p>
<p class="truncate">docs/garden/week-01/planting-notes</p>
<style>
.hint-only, .truncate { font-family: sans-serif; }
.hint-only { text-overflow: ellipsis; }
.truncate {
max-width: 12rem;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
What this markup means
.hint-only sets only text-overflow: ellipsis, so the path can still wrap or extend in visible overflow and no ellipsis is required to appear. .truncate sets max-width, overflow: hidden, and white-space: nowrap with the ellipsis, which is the usual single-line combination. The path is documentation text, not a file read.
Related: Sizing and overflow, Typography
MDN documentation → · CSS specification →