Case ce-0111-empty-elements-accumulate · Scenario scenario-empty-element-cleanup

Empty paragraph and span elements accumulate during editing

OS: Windows 11 Device: Desktop or Laptop Any Browser: Chrome 120.0 Keyboard: US Status: draft
empty cleanup dom chrome

Phenomenon

During editing operations, empty elements (empty paragraphs, divs, spans with no content) accumulate in the DOM. These elements cause layout issues and bloat the HTML.

Reproduction example

  1. Create content in contenteditable
  2. Apply formatting and remove it
  3. Delete text content
  4. Observe the DOM structure

Observed behavior

  • Empty <p> or <div> elements remain
  • Empty <span> elements with style attributes remain
  • DOM becomes bloated with empty elements
  • Layout may have unexpected spacing

Expected behavior

  • Empty elements should be cleaned up automatically
  • Or cleanup should be easy to implement
  • DOM should remain clean and minimal
  • No unnecessary empty elements

Browser Comparison

  • Chrome/Edge: Leaves empty elements (this case)
  • Firefox: More likely to leave empty elements
  • Safari: Most likely to accumulate empty elements

Notes and possible direction for workarounds

  • Implement cleanup logic to remove empty elements
  • Run cleanup after input events
  • Preserve at least one empty block for cursor placement
  • Remove empty spans, but keep structure if needed
  • Normalize DOM structure regularly
Before

Hello World

Formatted text
After Formatting Removal (Bug)

Hello World

After formatting removal, empty span tags remain
vs
✅ Expected

Hello World

Expected: Empty elements automatically cleaned up

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-0111-empty-elements-accumulate Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0127-empty-paragraph-after-delete Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0140-empty-span-style-attributes Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0159-empty-elements-after-format-remove Windows 11 Desktop or Laptop Any Safari 17.0 US draft
ce-0174-empty-div-after-list-removal 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.