JavaScript Element compositionupdate Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM event
Instance event

What You’ll Learn

The compositionupdate event fires when an IME (Input Method Editor) or other text composition system starts a new composition session. Learn addEventListener vs oncompositionupdate, CompositionEvent.data, how it pairs with compositionupdate / compositionend, and five try-it labs.

01

Kind

Instance event

02

Type

CompositionEvent

03

When

IME text changes

04

Handler

oncompositionupdate

05

Key field

event.data

06

Status

Baseline widely available

Introduction

Languages such as Chinese, Japanese, and Korean often use an IME. The user types phonetic or stroke hints; the system shows candidates; then a final character (or string) is committed into the field.

That whole flow is a composition session. compositionupdate means the session just began—before candidates settle and before the final character is committed. MDN’s classic example is starting a Chinese character with a Pinyin IME.

💡
Beginner tip

On compositionupdate, mark your UI as composing (pause live search, show a hint). Wait for compositionend before treating text as final.

Understanding compositionupdate

An instance event that answers: “Did an IME composition session just begin?”

  • Fires when a new composition session starts.
  • CompositionEvent — read data (and sometimes locale).
  • Siblingscompositionupdate, compositionend.
  • Useful for pausing search, showing “composing…” UI, custom editors.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

Use the event name with addEventListener, or set the handler property:

JavaScript
addEventListener("compositionupdate", (event) => { });

oncompositionupdate = (event) => { };

Event type

A CompositionEvent (inherits from UIEvent and Event).

Event properties

PropertyMeaning
dataCharacters generated by the input method for this event
localeLocale of the current input method (when available)

🔁 Composition Session Flow

  1. compositionstart — the IME session begins.
  2. compositionupdate — candidate / composing text changes (may fire many times).
  3. compositionend — session completes or is canceled; check event.data.

Ordinary Latin typing may never fire these events. They matter most when an IME is active.

⚖️ Composition vs input / beforeinput

APIRole during IME
composition*Session lifecycle (start / update / end)
beforeinputEdit about to apply; isComposing may be true
inputValue changed; may fire during and after composition

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("compositionupdate", fn)
Handler propertyel.oncompositionupdate = fn
Committed textevent.data
Log full IME flowAlso listen to start + update
MDN statusBaseline Widely available (Jul 2015)

🔍 At a Glance

Four facts to remember about compositionupdate.

Event type
CompositionEvent

data + locale

Means
IME update

Candidate changes

Pair with
start/end

Full session

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: compositionupdate event. To see live IME events, enable an IME (for example macOS Option+`, Windows Win+., or a CJK keyboard).

📚 Getting Started

Log composing text as the IME updates candidates (MDN style).

Example 1 — addEventListener("compositionupdate")

MDN idea: print event.data whenever composing text changes.

JavaScript
const inputElement = document.querySelector('input[type="text"]');

inputElement.addEventListener("compositionupdate", (event) => {
  console.log(`generated characters were: ${event.data}`);
});
Try It Yourself

How It Works

Without an active IME, this listener may stay quiet. During composition, event.data usually holds the current composing string and can change many times before compositionend.

Example 2 — oncompositionupdate Property

Same mid-session hook using the handler property.

JavaScript
const field = document.querySelector("input");

field.oncompositionupdate = (event) => {
  console.log("composition update:", event.data);
};

// Assigning again replaces the previous oncompositionupdate handler.
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Log, Preview & Count

Log the full IME trio, show a live preview, and count updates.

Example 3 — Log start / update / end

MDN live-example pattern: one handler for all three composition events.

JavaScript
const inputElement = document.querySelector('input[type="text"]');
const log = document.querySelector(".event-log-contents");

function handleEvent(event) {
  log.textContent += `${event.type}: ${event.data}\n`;
}

inputElement.addEventListener("compositionstart", handleEvent);
inputElement.addEventListener("compositionupdate", handleEvent);
inputElement.addEventListener("compositionend", handleEvent);
Try It Yourself

How It Works

Start opens the session. Updates (often many) show intermediate text; end commits or cancels. Notice how compositionupdate lines dominate a typical Pinyin session.

Example 4 — Live Composing Preview

Mirror event.data into a status line while the user composes.

JavaScript
const field = document.getElementById("name");
const status = document.getElementById("status");

field.addEventListener("compositionupdate", (event) => {
  status.textContent = "Preview: " + event.data;
});

field.addEventListener("compositionend", (event) => {
  status.textContent = "Committed: " + (event.data || field.value);
});
Try It Yourself

How It Works

Custom editors and teaching UIs often show the composing string separately from the committed value. Treat preview text as temporary.

Example 5 — Count Composition Updates

See how chatty an IME session can be—useful for debugging and demos.

JavaScript
const field = document.getElementById("q");
const out = document.getElementById("out");
let updates = 0;

field.addEventListener("compositionstart", () => {
  updates = 0;
  out.textContent = "Session started (0 updates)";
});

field.addEventListener("compositionupdate", (event) => {
  updates += 1;
  out.textContent = updates + " update(s) — last data: " + event.data;
});

field.addEventListener("compositionend", () => {
  out.textContent = "Session ended after " + updates + " update(s). Value: " + field.value;
});
Try It Yourself

How It Works

One short Pinyin character can still produce several compositionupdate events. Counting them helps explain why you should not fire expensive work on every update.

🚀 Common Use Cases

  • Showing a live preview of composing / candidate text via event.data.
  • Powering custom rich-text or chat editors that draw IME underlines themselves.
  • Debugging internationalization by logging every mid-session change.
  • Avoiding expensive work on every update (debounce until compositionend).
  • Pairing with compositionstart / compositionend for the full story.

🔧 How It Works

1

compositionstart fires

IME begins a new composition session on the focused control.

Start
2

compositionupdate fires

Composing / candidate text changes—often many times. Read event.data.

Update
3

User commits or cancels

IME finishes the session.

Decide
4

compositionend fires

Clear composing UI and treat text as finalized for this session.

📝 Notes

Universal Browser Support

compositionupdate is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Exact IME UI and shortcuts still depend on the operating system and language pack.

Baseline · Widely available

Element compositionupdate

Works across modern desktop and mobile browsers during an active IME composition session.

100% Widely available
Google Chrome Supported · Desktop & Android
Full support
Mozilla Firefox Supported · Desktop & Android
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Opera Supported · Modern versions
Full support
Internet Explorer Supported (legacy)
Supported
compositionupdate Baseline

Bottom line: Listen for compositionupdate to read live composing text; pair with start/end for the full IME session.

Conclusion

compositionupdate is the “composing text changed” signal. Use event.data for previews and debugging, but wait for compositionend before treating text as final.

Continue with contentvisibilityautostatechange, compositionend, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener("compositionupdate", ...)
  • Use event.data for temporary previews only
  • Log start/update/end together while debugging
  • Debounce heavy work until compositionend
  • Test with a real IME keyboard layout

❌ Don’t

  • Assume composition events fire for plain Latin typing
  • Treat every update as a final commit
  • Run expensive search/API calls on every update
  • Confuse composition with the everyday input event
  • Overwrite oncompositionupdate if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about compositionupdate

Composing text changed—preview only, then wait for end.

5
Core concepts
📄 02

CompositionEvent

data + locale

API
🔁 03

Between start/end

may fire many times

Order
🔎 04

Preview only

not final text

Pattern
🎯 05

Baseline

widely available

Compat

❓ Frequently Asked Questions

It fires when a new character is received during a text composition session controlled by an IME or similar system — for example while a user is entering a Chinese character with a Pinyin IME and the candidate text changes.
No. MDN marks Element compositionupdate as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A CompositionEvent (inherits from UIEvent). Useful properties include data (characters generated for this event) and locale (input method locale).
compositionstart begins a session, compositionupdate fires as the candidate text changes (often many times), and compositionend fires when the session completes or is canceled.
On macOS you can often use Option + ` to open an IME panel; on Windows, Win + . opens emoji/IME-related UI. Exact shortcuts depend on OS language settings. You can also switch to a CJK keyboard layout.
Use event.data to show a live preview of composing text if needed, but do not treat it as final. Keep search/autosave paused until compositionend.
Did you know?

MDN’s demo tips for opening IME UI: on macOS try Option+`; on Windows try Win+.. Your OS language settings still control which IMEs are installed.

Next: contentvisibilityautostatechange

Pause canvas and timers when content-visibility skips off-screen contents.

contentvisibilityautostatechange →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful