There are a few different ways to truncate multi-line text with CSS:

  1. Use the text-overflow: ellipsis property: This property will truncate the text and add an ellipsis (...) to the end of the visible text. To use this property, you'll need to set the overflow property to hidden and the white-space property to nowrap. For example:
.truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  1. Use the max-height and line-clamp properties: This method allows you to specify the maximum number of lines that should be displayed before truncating the text. To use this method, you'll need to set the max-height property to the maximum number of lines multiplied by the line height, and the line-clamp property to the maximum number of lines. For example:
.truncate {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  1. Use JavaScript: If you need to truncate text that is generated dynamically or based on user input, you may need to use JavaScript to truncate the text. There are a number of different ways to do this, but one common method is to split the text into an array of words, then join the words together until the text fits within a certain number of lines.

I hope these suggestions help! Let me know if you have any other questions.

Have any project in mind?

Send Inquiry

Copyright © 2024 All rights reserved