Caret stays in correct position when deleting next to non-editable in Firefox
OS: macOS 13+ · Device: Desktop (Mac) Any · Browser: Firefox 120+ · Keyboard: English (QWERTY)
Open case →Scenario
When deleting the last character before a non-editable "pill" or tag element (contenteditable="false") in a contenteditable div in Chrome, the caret (cursor) jumps to the end of the entire contenteditable div instead of staying adjacent to the remaining content.
When deleting characters adjacent to non-editable elements (e.g., tags, pills with contenteditable="false") in a contenteditable div, the caret unexpectedly jumps to the end of the entire editor in Chrome.
This issue occurs when:
<span contenteditable="false">)Chrome’s caret positioning algorithm appears to incorrectly calculate where the caret should go when:
contenteditable="false") is in the DOMSet display: inline-block on contenteditable:
.contenteditable {
display: inline-block;
}
Add zero-width space after non-editable elements:
// Insert ZWSP after non-editable element
const zwsp = document.createTextNode('\u200B');
nonEditableElement.parentNode.insertBefore(zwsp, nonEditableElement.nextSibling);
Use empty span as placeholder:
// Add empty span after non-editable element
const placeholder = document.createElement('span');
placeholder.innerHTML = ' ';
nonEditableElement.parentNode.insertBefore(placeholder, nonEditableElement.nextSibling);
Wrap editable content in separate div:
<div contenteditable="false">
<div contenteditable="true">editable content</div>
</div>
Programmatically restore caret position after deletion:
editor.addEventListener('input', (e) => {
const selection = window.getSelection();
// Check if caret jumped
if (caretJumped) {
// Restore position
const range = document.createRange();
range.setStartBefore(nonEditableElement);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
}
});
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-0266-caret-jump-non-editable-firefox-en | macOS 13+ | Desktop (Mac) Any | Firefox 120+ | English (QWERTY) | confirmed |
Open a case to see the detailed description and its dedicated playground.
OS: macOS 13+ · Device: Desktop (Mac) Any · Browser: Firefox 120+ · Keyboard: English (QWERTY)
Open case →Other scenarios that share similar tags or category.
When editing content inside an element with `position:relative`, the text caret (cursor) is completely invisible. Text can be typed and appears in the editor, but there's no visual feedback of where the insertion point is located.
On Chrome Mobile for Android, typing certain punctuation characters (commas, colons, semicolons, quotes, etc.) in the middle of a word causes the cursor to jump to the end of the word instead of staying at the insertion point.
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.
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.
When a contenteditable element or its parent has the CSS contain property, selection behavior may be affected. Selection may not extend beyond the contained element, and caret movement may be restricted.
Have questions, suggestions, or want to share your experience? Join the discussion below.