3

I am looking for a list of caracters and elements that may break HTML lines such as whitespaces but I can't find any page on the Internet with a definition of what is the normal HTML line break behavior. I have found those :

  • divisable space,
  • tab,
  • new line
  • Zero-width space (asian)
  • less "-"
  • Soft-hyphen

I am not expecting it to break in the "pre" tag, of course!

  • in HTML si br tag https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br – ScaisEdge Jan 28 '17 at 13:12
  • You mean if a div is too short for the text, what would make the text go to the next line http://stackoverflow.com/questions/8515365/are-there-other-whitespace-codes-like-nbsp-for-half-spaces-em-spaces-en-space – mplungjan Jan 28 '17 at 13:12

1 Answers1

5

If I understand correctly, you want to know what characters create a soft wrap opportunity, that is, they allow a line break in order to fit the content within the measure.

The answer is that it's not fully defined, and depends on the language:

In most writing systems, in the absence of hyphenation a soft wrap opportunity occurs only at word boundaries. Many such systems use spaces or punctuation to explicitly separate words, and soft wrap opportunities can be identified by these characters. Scripts such as Thai, Lao, and Khmer, however, do not use spaces or punctuation to separate words. Although the zero width space (U+200B) can be used as an explicit word delimiter in these scripts, this practice is not common.

[...] CSS does not fully define where soft wrap opportunities occur, however some controls are provided to distinguish common variations.

You can partially control this behavior using some CSS properties like

  • line-break, to specify how wrapping interacts with punctuation and symbols
  • word-break, which may allow soft wrap opportunities between letters
  • hyphens, to control whether hyphenation is allowed to create more soft wrap opportunities
  • overflow-wrap/word-wrap, which may allow arbitrary breaks within a word to prevent overflow

If you want the full list of characters that create a soft wrap opportunity, you can use JS:

var log = console.log;
console.log = Function.prototype;
console.config({maxEntries: Infinity});
console.log = log;

var test = document.createElement('div');
test.className = 'test';
document.body.appendChild(test);
for (var i=0; i<0xffff; ++i) {
  var char = String.fromCharCode(i);
  test.textContent = 'a' + char + 'b';
  if (test.clientHeight > 1) {
    console.log(i.toString(16) + ': ' + JSON.stringify(char));
  }
}
document.body.removeChild(test);
.test {
  width: 0;
  line-height: 1px;
}
div.as-console-wrapper {
  max-height: 100%;
}
Oriol
  • 274,082
  • 63
  • 437
  • 513
  • Yes I am looking for the soft wrap opportunity rules that are defined by the browsers and/or the systems, that makes the html lines stop at some point and continue next line. I am writting some javascript linecounter that measures words after words if a line fits in a text bloc, so I wonder if someone who knows precisely the source code of browsers or have typographical knowledge, can tell if I forgot rules in my list or not ? – Romain Guillaume Jan 28 '17 at 15:01
  • @RomainGuillaume You can use JS to get the full list – Oriol Jan 28 '17 at 15:40
  • Very nice demonstration of JS capabillities, very effective. Thank you! – Romain Guillaume Jan 28 '17 at 15:58