files/en-us/web/css/reference/properties/white-space-collapse/index.md
The white-space-collapse CSS property controls how {{Glossary("whitespace", "white space")}} inside an element is collapsed.
[!NOTE] The
white-space-collapseand {{CSSxRef("text-wrap-mode")}} properties can be declared together using the {{CSSxRef("white-space")}} shorthand property.
/* Keyword values */
white-space-collapse: collapse;
white-space-collapse: preserve;
white-space-collapse: preserve-breaks;
white-space-collapse: preserve-spaces;
white-space-collapse: break-spaces;
/* Global values */
white-space-collapse: inherit;
white-space-collapse: initial;
white-space-collapse: revert;
white-space-collapse: revert-layer;
white-space-collapse: unset;
The white-space-collapse property is specified as a single keyword chosen from the list of values below.
collapse
preserve
preserve-breaks
preserve-spaces
break-spaces
preserve, except that:
[!NOTE] Segment break characters are characters such as line feeds that cause text to break onto new lines.
[!NOTE] The CSS text module defines a
discardvalue for thewhite-space-collapseproperty to discard all white space in the element, however, this is not supported in any browsers.
{{CSSInfo}}
{{CSSSyntax}}
<h2 class="collapse">Default behavior;
all whitespace is collapsed
in the heading .</h2>
<h2 class="preserve">In this case
all whitespace is preserved
in the heading .</h2>
<h2 class="preserve-breaks">In this case only
the line breaks are preserved
in the heading .</h2>
<h2 class="preserve-spaces">In this case only
the spaces are preserved
in the heading .</h2>
.collapse {
white-space-collapse: collapse;
}
.preserve {
white-space-collapse: preserve;
}
.preserve-breaks {
white-space-collapse: preserve-breaks;
}
.preserve-spaces {
white-space-collapse: preserve-spaces;
}
h2 {
font-size: 1.6rem;
font-family: monospace;
border-bottom: 1px dotted #cccccc;
}
{{EmbedLiveSample("Examples", "100%", 350)}}
{{Specifications}}
{{Compat}}
white-space-collapse and {{CSSxRef("text-wrap-mode")}}: The {{CSSxRef("white-space")}} property.