Scenario

Placeholder interference with IME and DOM mutations

Technical analysis of how CSS and attribute-based placeholders disrupt text insertion and IME sessions.

ui
Scenario ID
scenario-placeholder-behavior

Details

Problem Overview

Standard <input> and <textarea> elements have native placeholder support. contenteditable does not. Developers typically simulate placeholders using the CSS :empty:before selector or by injecting a pseudo-node. This simulation often creates a “Race Condition” where the browser’s logic for removing the placeholder collides with the user’s logic for inserting text, particularly during the startup of an IME session.

Observed Behavior

Scenario 1: The Korean IME Decimation (Chrome/Android)

In Chrome 131+ on Android, when the first character of a Korean syllable is typed, the DOM mutation triggered by CSS removing the :before placeholder (because the element is no longer :empty) causes the browser to reset its internal IME buffer.

/* Chrome Logic Loop */
// 1. User types 'ㅎ'
// 2. Element is no longer :empty
// 3. CSS pseudo-element is destroyed
// 4. Mutation event clears the text node 'ㅎ' incorrectly

Scenario 2: Layout Shift on Focus

In Safari, the placeholder often remains visible until a character is typed, but if the placeholder has different padding/font than the text, focusing it can cause a “jump” that moves the caret unexpectedly.

Impact

  • Character Loss: The first character of every input session is erased or ignored.
  • Incorrect Positioning: The caret ends up inside the pseudo-element or at the documents start.
  • Accessibility: Screen readers often announce the placeholder text after the user has already started typing.

Browser Comparison

  • Chromium: Vulnerable to “Mutation Collision” specifically on mobile.
  • WebKit: Prone to layout jumps and caret miscalculations.
  • Gecko: Generally handles :empty transitions safely but may fail to render a caret in zero-height divs.

Solutions

1. Opacity-based Toggling

Instead of allowing :empty to destroy the node, toggle its visibility or opacity based on a manually maintained is-empty class or the focus state.

/* Avoid content: "" changes mid-type */
[contenteditable]::before {
  content: attr(placeholder);
  opacity: 0.5;
}
[contenteditable]:not(:empty)::before,
[contenteditable]:focus::before {
  display: none; /* or visibility: hidden */
}

2. Manual Placeholder Removal on Focus

Explicitly remove the placeholder state when the element is focused, before any composition events fire.

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-0056-contenteditable-with-placeholder macOS Ubuntu 22.04 Desktop or Laptop Any Safari 120.0 US draft
ce-0568-chrome-android-placeholder-korean-ime Android 14.0 Smartphone Any Chrome 131.0 Korean (IME) confirmed

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

This scenario affects multiple languages. Cases are grouped by language/input method below.

Korean

1 case

US

1 case

Related Scenarios

Other scenarios that share similar tags or category.

Tags: ime

beforeinput and input events have different inputType values

During IME composition or in certain browser/IME combinations, the beforeinput event may have a different inputType than the corresponding input event. For example, beforeinput may fire with insertCompositionText while input fires with deleteContentBackward. This mismatch can cause handlers to misinterpret the actual DOM change and requires storing beforeinput's targetRanges for use in input event handling.

1 case
Tags: ime

Selection mismatch between beforeinput and input events

The selection (window.getSelection()) in beforeinput events can differ from the selection in corresponding input events. This mismatch can occur during IME composition, text prediction, or when typing adjacent to formatted elements like links. The selection in beforeinput may include adjacent formatted text, while input selection reflects the final cursor position.

1 case
Tags: ime

Browser translation breaks contenteditable editing

When browser translation features (like Google Translate) are activated, they manipulate the DOM by replacing text content and injecting elements. This can break contenteditable functionality, causing cursor positioning issues, event handling problems, and IME composition failures.

1 case

Comments & Discussion

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