The white-space property sets how white space (spaces and line breaks) is handled.
p {
white-space: nowrap;
}
| Property | Value | Explanation |
|---|---|---|
| white-space | normal | multiple white space is collapsed into a single space (default) |
| nowrap | prevents a line break |
|
| pre | preserves white spaces (MSIE is supported in Standards mode only) |
nowrap
<html> <head> <title>TAG index</title> <style type="text/css"> #example { white-space: nowrap; } </style> </head> <body> <p>Some text some text some text. Some text ...</p> <p id="example">Some text some text some text. Some text ...</p> </body> </html>
pre
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>TAG index</title> <style type="text/css"> #example { white-space: pre; } </style> </head> <body> <p>The text to which the pre value is specified.</p> <div id="example"> function PopTag() { if (!document.getElementById) { alert("Hello"); return; } } </div> <p>The text to which the pre value is not specified.</p> <div> function PopTag() { if (!document.getElementById) { alert("Hello"); return; } } </div> </body> </html>
The text to which the pre value is specified.
The text to which the pre value is not specified.