Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Preventing Line Breaks

For proper arrangement and appearance of text, it may be necessary to prevent the browser from inserting a line break at certain places.

There are three ways to inform the browser not to insert a line break.

Substituting   for space —

The   code can be used instead of a regular keyboard space between words.

Generally, a browser assumes it is okay to insert a line break where a keyboard space character is used. Substituting   for the space character tells the browser not to insert a line break.

Example:

yellow-tailed warbler

Using <nobr> and </nobr> tags —

The <nobr> and </nobr> pair of HTML markup tags can be used to prevent line breaks.

When text or other content is between <nobr> and </nobr>, the browser is told not to insert extra line breaks.

Example:

<nobr>yellow-tailed warbler</nobr>

Using white-space:nowrap CSS —

The white-space:nowrap CSS declaration can be used to prevent line breaks.

The CSS can be used inline or as a class. When text or other content is affected by white-space:nowrap CSS, the browser is told not to insert extra line breaks.

Example with inline CSS:

<span style="white-space:nowrap;">yellow-tailed warbler</span>

Example with a CSS class:

<style type="text/css">
.nowrap { white-space:nowrap; }
</style>
<span class="nowrap">yellow-tailed warbler</span>

Choosing which of the above three methods to use depends on situation and personal preference.

Using &nbsp; generally is the quickest, for me, when two words need to be kept on the same line. Another quick one is <nobr> and </nobr> tags, especially when more than two words need to be kept together or an image with a word.

The white-space:nowrap CSS is declared in most of my web page headers. Typing class="nowrap" is both fast and common for me because the CSS rule is already declared.

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC