Scenario

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.

formatting
Scenario ID
scenario-list-formatting-persistence

Details

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.

Observed Behavior

Scenario 1: Applying bold formatting to text in a list item

  • Chrome/Edge: Formatting is applied, but may be lost when pressing Enter to create a new list item
  • Firefox: Formatting may not persist when editing list items
  • Safari: Formatting can be lost unexpectedly

Scenario 2: Pasting formatted content into a list item

  • Chrome/Edge: May preserve formatting but lose list structure
  • Firefox: May convert list items to paragraphs
  • Safari: May create unexpected nested structures

Scenario 3: Pasting a list into another list

  • Chrome/Edge: May create nested lists or flatten the structure
  • Firefox: May lose the nested list structure
  • Safari: May create malformed HTML

Scenario 4: Applying formatting across multiple list items

  • Chrome/Edge: May break the list structure
  • Firefox: May convert list items to paragraphs
  • Safari: Behavior is inconsistent

Impact

  • Loss of formatting when editing lists
  • Unexpected list structure changes
  • Difficulty maintaining consistent list appearance
  • User frustration when formatting is lost

Browser Comparison

  • Chrome/Edge: Generally better at preserving formatting, but list structure may be affected
  • Firefox: More likely to lose formatting or list structure
  • Safari: Most inconsistent behavior

Workaround

Intercept formatting operations and ensure list structure is preserved:

element.addEventListener('beforeinput', (e) => {
  if (e.inputType === 'formatBold' || e.inputType === 'formatItalic') {
    const selection = window.getSelection();
    if (selection.rangeCount === 0) return;
    
    const range = selection.getRangeAt(0);
    const listItems = Array.from(range.commonAncestorContainer.closest('ul, ol')?.querySelectorAll('li') || [])
      .filter(li => range.intersectsNode(li));
    
    if (listItems.length > 0) {
      e.preventDefault();
      // Apply formatting while preserving list structure
      applyFormattingToSelection(e.inputType, range, listItems);
    }
  }
});

element.addEventListener('paste', (e) => {
  const selection = window.getSelection();
  if (selection.rangeCount === 0) return;
  
  const range = selection.getRangeAt(0);
  const listItem = range.startContainer.closest('li');
  
  if (listItem) {
    e.preventDefault();
    // Handle paste in list item, preserving list structure
    handlePasteInListItem(e.clipboardData, range, listItem);
  }
});

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-0116-list-formatting-lost-paste Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0124-list-formatting-bold-lost Windows 11 Desktop or Laptop Any Firefox 120.0 US draft
ce-0163-list-formatting-across-items Windows 11 Desktop or Laptop Any Chrome 120.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: formatting, bold, italic

Nested formatting elements create complex DOM structures

Applying multiple formatting operations (bold, italic, underline, etc.) creates nested HTML elements that can become complex and hard to manage. Browsers handle nested formatting differently, and the resulting DOM structure can be inconsistent.

3 cases
Tags: formatting, bold, italic

Typing adjacent to formatted elements causes unexpected behavior

When typing text next to formatted elements (links, bold, italic, etc.) in contenteditable, the input events may include the formatted element's text in event.data, selection ranges may include the formatted element, and text may be inserted into the formatted element instead of after it. This occurs across different browsers and input methods.

1 case
Tags: formatting

Code block editing behavior varies across browsers

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.

4 cases
Tags: formatting

execCommand is deprecated but still widely used for formatting

The document.execCommand() API, which is commonly used to apply formatting (bold, italic, etc.) in contenteditable regions, has been deprecated. However, there is no complete replacement, and many implementations still rely on it. This creates uncertainty about future browser support.

1 case

Comments & Discussion

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