Scenario

Selection range is incorrect when selecting across multiple elements

When selecting text that spans across multiple HTML elements (e.g., p, div, span) in a contenteditable region, the selection range may not accurately reflect the visual selection. The Selection and Range APIs may return incorrect boundaries.

selection
Scenario ID
scenario-selection-range-accuracy

Details

When selecting text that spans across multiple HTML elements (e.g., <p>, <div>, <span>) in a contenteditable region, the selection range may not accurately reflect the visual selection. The Selection and Range APIs may return incorrect boundaries.

Observed Behavior

  • In Edge/Chrome, the selection range boundaries may not match the visual selection.
  • The Range.startOffset and Range.endOffset may be incorrect when spanning element boundaries.

Reproduction Steps

  1. Create a contenteditable div with nested elements: <p>First</p><p>Second</p>.
  2. Select text that spans from the middle of the first paragraph to the middle of the second paragraph.
  3. Use JavaScript to inspect the Selection object.
  4. Observe that reported positions mismatch the visual highlight.

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-0033-selection-range-incorrect Windows 11 Desktop Any Edge 120.0 US confirmed

Cases

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

Related Scenarios

Other scenarios that share similar tags or category.

Tags: selection, range

Selection restoration after DOM manipulation is unreliable

After programmatically manipulating the DOM in a contenteditable element, restoring the text selection (cursor position) is unreliable across browsers. The selection may be lost, moved to an incorrect position, or become invalid.

5 cases
Tags: selection

Browser zoom causes caret and selection positioning issues

When the browser is zoomed (or content is scaled via CSS transforms), caret position and text selection in contenteditable elements can become inaccurate. Clicking at a certain position places the caret elsewhere, and selection highlights may not match the visual selection.

1 case
Tags: selection

Cursor disappears with contenteditable="false" elements

When contenteditable='false' elements are placed inside a contenteditable container, the cursor may disappear or become invisible in certain browsers, making it difficult for users to determine the text insertion point.

0 cases

Comments & Discussion

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