The white-space property in CSS is used to control how white space within an element is handled. It allows you to define whether spaces, tabs, and line breaks should be collapsed or preserved, influencing the layout and presentation of text.
Note: The white-space property can take values like normal , nowrap , and pre .
Syntax:
/* Collapsing consecutive white spaces and wrapping text as needed */ p { white-space: normal; }
Features:
white-space Property:
normal : Collapses consecutive white spaces and wraps text as needed.
nowrap : Prevents text from wrapping to the next line.
pre : Preserves both spaces and line breaks, displaying text exactly as it appears in the code.
- Line Breaking: The
white-space property also affects how the browser handles line breaks, especially in scenarios like long URLs or code snippets.
pre-line and pre-wrap : These values offer variations of preserving white space and line breaks, providing more flexibility.
|