Specifying a preferred line break point in HTML text in a responsive design

Forethinker picture Forethinker · Aug 14, 2013 · Viewed 72.2k times · Source

I was wondering if there is a CSS or javascript magic that could place a marker in an html text so that the browser know where the line break creation is preffered when the text gets cramped. Is there such thing?

Answer

jomo picture jomo · Jun 23, 2014

I think this works very well:

span.line {
  display: inline-block;
}


<p>
  <span class="line">This text should break</span>
  <span class="line">after the word "break"</span>
</p>

The text still breaks on other places when there is not enough space:

screenshot

open demo