CSS White Space

CSS white-space property specifies the white spaces in an element. You can control the white spaces using white-space property.
Here is a list of white-space property values:

Values Description
normal It is the default value.
nowrap Multiple whitespaces are collapsed into one but the text will never wrap to the next line. The line will break only when <br> tag is used.
pre Sequences of white space are preserved. Lines will only break at newline characters and using the <br> tag.
pre-wrap Sequences of white space are preserved. Lines will only break at newline characters, using the <br> tag and as necessary to fill line boxes.
pre-line Sequences of white space are collapsed. Lines will only break at newline characters, using the <br> tag and as necessary to fill line boxes.
initial It is used to set the white space with its default value.
inherit It is used to inherit the white space from its parent value.


white-space Property Example

Here is an example using white-space property:

Example:

p.nowrap {
  white-space: nowrap;
}

p.pre {
  white-space: pre;
}

p.normal {
  white-space: normal;
}

Run Example