Cutting text off in CSS
One line is a different technique from three lines, and both need a width to work against.
.one-line {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
min-inline-size: 0;
}
.three-lines {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
.url { overflow-wrap: anywhere; hyphens: auto; }
.balanced { text-wrap: balance; }
.pretty { text-wrap: pretty; }
How it works
text-overflow: ellipsisneedsnowrapand anoverflowthat is not visible.line-clamphandles several lines and needs no fixed height.overflow-wrap: anywhereis the escape hatch for an unbreakable URL.
Keywords and builtins used here
balanceddisplayhyphensoverflowprettyurl
The run, in numbers
- Lines
- 17
- Characters to type
- 323
- Tokens
- 71
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 47 seconds.
Step 1 of 3 in Text & scrollers, step 7 of 13 in Styling components.