Widows are a classic typographic “no-no”, essentially leaving a single word by itself at the end of a paragraph can decimate your layout. With print collateral, there is the possibility of using a soft-return to make sure there are at least two words to end the paragraph. However, with no soft-return in code, the best option is to opt for using a non-breaking space of “nbsp;”. Any two words with a non-breaking space between them will always be on the same line whenever moved to the next line. Using non-breaking spaces on the last two words of your paragraph will ensure that there will be no widows no matter what device you are on.

Although adding a non-breaking space between the last two words is indeed a great way to rid yourself of pesky widows, imagine putting that on every paragraph tag in your editor. I’ve done it, and trust me you will make a mistake. The pen below is a short snippet of JavaScript that will take select the last two words in every paragraph tag and attach the much coveted non-breaking space between them.