How To Truncate Multiple Lines Of Text With CSS

CSS

27/02/2023


Truncating, for example, any text beyond the 2nd line is fairly simple with the following properties.

CSS
.text-box {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2; /* From which line on to truncate */
overflow: hidden;
}

Property -webkit-line-clamp does most of the magic, but needs to be used in combination with the properties above to work. This solution enjoys strong support among browsers, which makes it the most desirable method of achieving multiline truncation.


WRITTEN BY

Code and stuff