The white-space property controls whether and how white space inside the element is collapsed, and whether lines may wrap at unforced “soft wrap” opportunities.
Overview tablenormal
whiteSpace
white-space: normal
white-space: nowrap
white-space: pre
white-space: pre-line
white-space: pre-wrap
normal
, but content does not wrap to the next line.
normal
, this value collapses consecutive spaces and allows wrapping, but preserves segment breaks in the source as forced line breaks.
pre
, but allows wrapping (like normal
's wrapping).
See the live example that has all the properties implemented side by side for comparison.
.white-space--nowrap {
white-space:nowrap;
}
.white-space--normal {
white-space:normal;
}
.white-space--pre {
white-space:pre;
}
.white-space--pre-wrap {
white-space:pre-wrap;
}
.white-space--pre-line {
white-space:pre-wrap;
}
body {
font-size: large;
width: 500px;
}
p {
background-color: #ddd;
}
Notes
Whitespace, such as line breaks, spaces, and tabs, is collapsed by default in HTML documents. You can use the nonbreaking space entity ( )
to add extra spaces to an object when the white-space property is set to normal or nowrap. You can add extra line breaks using the br element.
Reference
pre
Other Resources
CSS Enhancements in Internet Explorer 6
Mozilla Developer Network : Article
Microsoft Developer Network: [Windows Internet Explorer API reference Article]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4