Scenario

List item deletion behavior varies across browsers

When pressing Backspace or Delete at the beginning or end of a list item, the behavior varies significantly across browsers. Some browsers delete the list item and merge with adjacent content, while others may delete the entire list or create unexpected DOM structures.

formatting
Scenario ID
scenario-list-item-deletion

Details

When pressing Backspace or Delete at the beginning or end of a list item (<li>), the behavior varies significantly across browsers. Some browsers delete the list item and merge with adjacent content, while others may delete the entire list or create unexpected DOM structures.

Observed Behavior

Scenario 1: Backspace at the beginning of first list item

  • Chrome/Edge: Deletes the list item and converts it to a paragraph, or merges with previous content
  • Firefox: May delete the entire list or create nested structures
  • Safari: Behavior may differ, sometimes creating empty list items

Scenario 2: Delete at the end of last list item

  • Chrome/Edge: Deletes the list item and merges with following content
  • Firefox: May delete the list item or the entire list
  • Safari: May create unexpected DOM structures

Scenario 3: Backspace on empty list item

  • Chrome/Edge: Removes the list item, may remove the entire list if it’s the last item
  • Firefox: May remove the list item or create empty paragraphs
  • Safari: Behavior varies

Impact

  • Inconsistent user experience across browsers
  • Unexpected DOM structure changes
  • Loss of list formatting when users expect to delete text
  • Difficulty in implementing consistent list editing behavior

Browser Comparison

  • Chrome/Edge: Generally more predictable, converts list items to paragraphs when appropriate
  • Firefox: May be more aggressive in removing list structure
  • Safari: Behavior can be inconsistent, sometimes creating malformed HTML

Workaround

When handling list item deletion, intercept beforeinput events and implement custom deletion logic:

element.addEventListener('beforeinput', (e) => {
  if (e.inputType === 'deleteContentBackward' || e.inputType === 'deleteContentForward') {
    const selection = window.getSelection();
    if (selection.rangeCount === 0) return;
    
    const range = selection.getRangeAt(0);
    const listItem = range.startContainer.closest('li');
    
    if (listItem) {
      // Check if cursor is at the beginning/end of list item
      const isAtStart = range.startOffset === 0 && 
                       range.startContainer === listItem.firstChild;
      const isAtEnd = range.endOffset === (range.endContainer.textContent?.length || 0) &&
                      range.endContainer === listItem.lastChild;
      
      if (isAtStart || isAtEnd) {
        e.preventDefault();
        // Implement custom list item deletion logic
        handleListItemDeletion(listItem, e.inputType);
      }
    }
  }
});

References

Scenario flow

Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.

React Flow mini map

Variants

Each row is a concrete case for this scenario, with a dedicated document and playground.

Case OS Device Browser Keyboard Status
ce-0097-list-item-deletion-chrome Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0098-list-item-deletion-firefox Windows 11 Desktop or Laptop Any Firefox 120.0 US draft
ce-0151-list-item-empty-after-delete Windows 11 Desktop or Laptop Any Safari 17.0 US draft

Browser compatibility

This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.

Confirmed
Draft
No case documented

Cases

Open a case to see the detailed description and its dedicated playground.

Related Scenarios

Other scenarios that share similar tags or category.

Tags: deletion, backspace, delete

Image deletion behavior varies across browsers

Deleting images from contenteditable elements behaves differently across browsers. Some browsers delete the image cleanly, while others may leave empty elements, break the DOM structure, or require multiple delete operations.

3 cases
Tags: list

List formatting is lost when editing list items

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.

3 cases
Tags: list

Nested list editing behavior is inconsistent

When editing nested lists (lists within list items), the behavior of Enter, Backspace, Delete, and Tab keys varies significantly across browsers. Creating, editing, and deleting nested list items can result in unexpected DOM structures or lost formatting.

3 cases
Category: formatting

Background color changes behave inconsistently

Changing background color (highlighting) in contenteditable elements behaves inconsistently across browsers. Background colors may be applied as inline styles, may not persist when typing, or may interfere with text selection. The behavior differs from text color changes.

3 cases

Comments & Discussion

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