skip to Main Content

Is there a CSS property that will make text try to fit onto 2 lines?

enter image description here

I could use a non-breaking space character to prevent a single orphaned word, but I thought there was a smarter property for new browsers which makes the text intelligently wrap so that both lines are of a similar length?

2

Answers


  1. There is a rather new CSS property called text-wrap. You can set it to balance, although the property is only supported in Edge, Chrome and Opera:
    https://caniuse.com/css-text-wrap-balance

    p {
      max-width: 250px;
    }
    
    p.balance {
      text-wrap: balance;
    }
    <p>this is my text and i dont like how it wraps</p>
    <p class="balance">this is my text and i dont like how it wraps</p>
    Login or Signup to reply.
  2. You could make the whole thing in a div with a specified width and adjust the width until it made the lines equal.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search