CSS white-space property

CSS white-space

CSS white-space is used to determine how the white-space in an element should be handled.

Following are the values used in CSS white-space property,

  • normal : Sequences of whitespace are collapsed to form a single whitespace, and the text will be wrapped and form a new line when necessary.
  • nowrap : Sequences of whitespace are collapsed to form a single whitespace, the text will not be wrapped to form a new line, until a <br> tag is used.
  • pre : Browser preserve the whitespace. Line breaks are wrapped by text
  • pre-line : Sequences of whitespace are collapsed to form a single whitespace, the text will wrap only when necessary.
  • pre-wrap : Browser preserve the whitespace, the text will wrap only when necessary and on line breaks.

nowrap value for css white-space property

Sequences of whitespace are collapsed to form a single whitespace, and the text will not be wrapped and the text will continue in the same line.

Example

Try Yourself

pre value for css white-space property

Whitespace are not collapsed, and the text will not be wrapped and the text will continue in the same line.

Example

Try Yourself

pre-line value for css white-space property

Sequences of whitespace are collapsed to form a single whitespace, and the text will be wrapped and form a new line when necessary.

Example

Try Yourself

pre-wrap value for css white-space property

Whitespace are not collapsed, and the text will be wrapped and form a new line when necessary.

Example

Try Yourself