style.whiteSpace (Property)

Controls how the browser should treat white space characters within the document source when it is rendered on the page.

Availability:

CSS level - 1
DOM level - 2
JavaScript - 1.5
JScript - 5.5
Internet Explorer - 5.5
Netscape - 6.0
Property/method value type:String primitive
JavaScript syntax:-myStyle.whiteSpace
CSS syntax:white-space: aControl
Argument list:aControlA white space control value

When the HTML document source is authored, the browser by default will ignore any text formatting within the document apart from that enclosed in <PRE> tags. Between words, multiple spaces are collapsed to single spaces and carriage returns are ignored.

The following keywords can be used to control whitespace handling in the browser:

With the normal keyword, the browser behaves as it normally would.

The nowrap keyword forces the browser to ignore line breaks. There is an implication that white space should be preserved, otherwise this setting is no different to the normal keyword.

The pre keyword honors all line breaks and whitespace in the text. Setting the pre keyword in this property retains the proportional font and simply leaves linebreaks and whitespace intact, unlike text that is enclosed in <PRE> tags, which will be rendered in a monospace font. This means that whitespace used for alignment may still not do what you expect although it may be a way of indenting text. It is not clear from the available documentation whether <BR> tags are honored inside a block styled with the pre keyword, but it is likely that they are which is also not the case when enclosing the text inside <PRE> tags. Netscape 6.0 does in fact honor <BR> tags inside an element styled with the pre value.

Warnings:

See also:JSSTag.whiteSpace