5 August 2024

To limit a div to a maximum of two rows of text in CSS, you can use the combination of line-clamp, display: -webkit-box, and other related properties. In this example I set the width to 50px for the div and line clamp is after 2 lines. This does require webkit, but is supported by modern browsers.

Source code viewer
  1. .text {
  2. display: -webkit-box;
  3. -webkit-box-orient: vertical;
  4. -webkit-line-clamp: 2;
  5. overflow: hidden;
  6. text-overflow: ellipsis;
  7. width: 50px;
  8. }
  9. <div class="text">
  10. This is a paragraph that will be limited to just two rows. It will be expanded with ellipsis.
  11. </div>
Programming Language: HTML