Case ce-0102-consecutive-spaces-collapsed · Scenario scenario-content-normalization

Multiple consecutive spaces are collapsed to single space

OS: Windows 11 Device: Desktop or Laptop Any Browser: Chrome 120.0 Keyboard: US Status: draft
whitespace space html all-browsers

Phenomenon

When typing multiple consecutive spaces in a contenteditable element, all browsers collapse them into a single space by default (following HTML whitespace rules). This differs from native text inputs and can be unexpected for users.

Reproduction example

  1. Focus a contenteditable element
  2. Type multiple spaces (e.g., press Space 5 times)
  3. Observe the DOM

Observed behavior

  • All consecutive spaces are collapsed to a single space in the DOM
  • This follows HTML whitespace collapsing rules
  • Visual appearance shows only one space
  • Different from <input> and <textarea> behavior

Expected behavior

  • Multiple spaces should be preserved (if needed)
  • Or behavior should be clearly documented
  • Users should understand why spaces are collapsed

Browser Comparison

  • All browsers: Collapse consecutive spaces (HTML standard)
  • Workaround: Use white-space: pre-wrap CSS or &nbsp; entities

Notes and possible direction for workarounds

  • Use CSS white-space: pre-wrap to preserve spaces
  • Intercept space insertion and use &nbsp; for multiple spaces
  • Document this behavior for users
  • Consider if preserving spaces is necessary for the use case
Before
Hello
Basic text
→
After 5 Spaces (Bug)
Hello
5 Space key presses, only one space remains in DOM (HTML whitespace collapse rule)
vs
✅ Expected (with CSS)
Hello
Expected: Multiple spaces preserved when using white-space: pre-wrap

Browser compatibility matrix

This matrix shows which browser and OS combinations have documented cases for this scenario. The current case is highlighted. Click on a cell to view other cases.

Current case
Confirmed
Draft
— No case documented

All variants (detailed table)

Complete list of all cases for this scenario with full environment details.

Case OS Device Browser Keyboard Status
ce-0102-consecutive-spaces-collapsed Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0117-nbsp-converted-to-space Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0153-nbsp-line-break-prevention Windows 11 Desktop or Laptop Any Chrome 120.0 US draft

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: Windows 11
Device: Desktop or Laptop Any
Browser: Chrome 120.0
Keyboard: US
Your environment
Sample HTML:
Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.