white-space - HTML CSS CSS Property

HTML CSS examples for CSS Property:white-space

Description

The white-space CSS property controls how to handle white-space such as spaces, tabs, and newline characters.

The following table summarizes the white-space Property.

Item Value
Default value: normal
Applies to:All elements
Inherited:yes
Animatable: No.

Syntax

The syntax of the property is as follows:


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

Property Values

The following table describes the values of this property.

Value Description
normal Collapse whitespace into a single whitespace. This is default value.
nowrap Collapses whitespace as for normal, but suppresses line breaks within text.
pre Acts like the <pre> tag in HTML
pre-line whitespace collapse into a single space. Line breaks preserved.
pre-wrap Whitespace is preserved by the browser. Text will wrap when necessary, and on line breaks
initial Sets this property to its default value.
inherit take the value of its parent element white-space property.

The example below shows the white-space property.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>Example of CSS white-space property</title>
  <style type="text/css">
    code {<!--from w  w  w  . jav a  2 s .co m-->
      white-space: pre;
    }
    p {
      white-space: nowrap;
    }
    </style>
 </head>
 <body>
  <div>
   <code> code { white-space: pre; } </code>
  </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. </p>
 </body>
</html>

Related Tutorials