white-space

Description

white-space declares how whitespace is handled during layout.

ItemValue
Initial value normal
Inherited No.
Version CSS1
JavaScript syntax object.style.whiteSpace="pre"
Applies to All elements.

Syntax and Property Values


white-space: normal | pre | nowrap | pre-wrap | pre-line | inherit 

The property values are listed in the following table.

ValueDescription
normal Default value. Collapse to a single whitespace. Wrap text if necessary.
nowrap Collapse to a single whitespace. Text not wrap to the next line.
pre Preserve whitespace. Act as <pre> tag
pre-line Collapse to a single whitespace. Wrap text on line breaks
pre-wrap Preserve whitespace. Wrap text on line breaks
inherit Inherit white-space property from parent element

Example


<!DOCTYPE HTML>
<html>
<head>
  <style type="text/css">
    p {<!--  www  .j  ava  2 s.co m-->
      white-space: pre;
      margin: 0;
    }

  </style>
</head>
<body>
<div>
  <p>  this is a test. this is a test. this is a test. 
  this is a test. this is a test. this is a test. 
  this is a test. this is a test. this is a test. 
  this is a test. this is a test. this is a test. 
  this is a test. this is a test. this is a test. 
  this is a test. </p>
</div>
</body>
</html>

Click to view the demo

The code above generates the following result.

white-space




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference