HTML CSS examples for CSS Property:white-space
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. |
The syntax of the property is as follows:
white-space: normal | pre | nowrap | pre-line | pre-wrap | initial | inherit
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.
<!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>