Multiple consecutive spaces are collapsed to single space
OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →Scenario
Architecting a consistent document state by neutralizing browser inconsistencies in HTML insertion and character encoding.
Every browser inserts different HTML when a user pastes or hits “Enter.” A robust editor must normalize this “Browser Soup” into a predictable internal schema to prevent data corruption and layout breakage.
When pasting from external sources (Word, Excel, Web), browsers inject massive amounts of hidden meta-data and proprietary CSS inside <style> blocks. Strict sanitization is required to strip non-standard attributes.
Browsers follow HTML rules, which collapse consecutive spaces into one. To maintain visual fidelity, editors often use Non-breaking spaces ( ).
blocks CSS line-wrapping, causing layout overflows. This is severe in plaintext-only mode.Rapid editing often leaves empty <span>, <b>, or <div> tags in the DOM. These “Ghost Tags” don’t affect visuals but break selection logic and node-count based features.
Interrupt the paste or beforeinput event and run the incoming HTML through a DOMParser. Apply a strict whitelist of tags and attributes before allowing the insertion.
Prefer white-space: pre-wrap for preserving layouts rather than relying on chains. If manual intervention is required, use a beforeinput handler to insert \u00A0 only when a trailing space is detected.
Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.
Each row is a concrete case for this scenario, with a dedicated document and playground.
| 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 |
This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.
| Browser | Windows |
|---|---|
| Chrome |
Open a case to see the detailed description and its dedicated playground.
OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →OS: Windows 11 · Device: Desktop or Laptop Any · Browser: Chrome 120.0 · Keyboard: US
Open case →Other scenarios that share similar tags or category.
After pasting content into a contenteditable region, the caret position does not end up at the expected location, sometimes jumping to the beginning of the pasted content or to an unexpected position.
When using the Clipboard API (navigator.clipboard.readText() or navigator.clipboard.read()) to programmatically paste content into a contenteditable region, the paste operation may fail or not work as expected.
Editing text within code blocks (<pre><code>) in contenteditable elements behaves inconsistently across browsers. Line breaks, indentation, whitespace preservation, and formatting may be handled differently, making it difficult to maintain code formatting.
When inserting images into contenteditable elements, the behavior varies significantly across browsers. Images may be inserted as <img> tags, as base64 data URLs, or may not be supported at all. The size, positioning, and editing behavior also differs.
When editing text within list items, formatting such as bold, italic, or links may be lost or behave unexpectedly. The list structure itself may also be lost when certain operations are performed, such as pasting content or applying formatting.
Have questions, suggestions, or want to share your experience? Join the discussion below.