Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

white-space-collapse — collapsing white space

The white-space-collapse property controls spaces, tabs, and segment breaks in text. It lets you configure white-space preservation independently of automatic line wrapping.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

white-space-collapse: collapse | discard | preserve | preserve-breaks | preserve-spaces | break-spaces;

white-space-collapse is inherited and initially collapse. It changes rendering, not document data. It is a longhand of white-space; automatic wrapping is controlled separately by text-wrap-mode.

collapse collapses white space; segment breaks can become a space or disappear depending on context. preserve retains spaces, tabs, and forced line breaks. preserve-breaks collapses spaces and tabs but retains line breaks. preserve-spaces preserves sequences while converting tabs and segment breaks to spaces.

break-spaces behaves like preserve, but allows wrapping after each preserved space or tab. Trailing spacing occupies space and affects intrinsic sizing instead of hanging outside the line. The draft defines discard to remove all white space; this specification section remains under discussion.

Do not equate draft syntax with browser support, especially for discard and preserve-spaces. Check the target implementation; the example requires local verification.

Examples

<!doctype html>
<meta charset="utf-8">
<title>white-space-collapse</title>
<style>
  .sample {
    white-space: normal;
    font: 20px/1.5 monospace;
    width: 20ch;
    border: 1px solid;
  }
  .keep { white-space-collapse: preserve-breaks; }
</style>
<div class="sample">A   B
C   D</div>
<div class="sample keep">A   B
C   D</div>

Result

A B C D
A B
C D

Run the example locally in the target browser and compare the rendered text with the expected output.

Sources