In JavaScript, compositionend fires when a text composition system such as an Input Method Editor (IME) completes or cancels the current composition session (MDN) — for example after finishing a Chinese character with Pinyin.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for compositionend. Start with this line.
JavaScript
addEventListener("compositionend", fn)
Call
What it does
addEventListener("compositionend", fn)
Primary signature.
Built into the browser. Listen with el.addEventListener("compositionend", …) — no import required.
Library declarations
JavaScript
addEventListener("compositionend", fn)
Parameters
Parameter
Description
Event name
Required. "compositionend"
Handler prop
Optional. oncompositionend
event.locale
Optional. Deprecated · Non-standard — avoid
Return Value
Return Value
Description
*
Fires as an Element event (listener receives the Event object).
JavaScript Examples
Example 1 — Listen and Log data (MDN)
Log the characters generated when composition ends.
compositionstart:
compositionupdate: ni
compositionupdate: 你
compositionend: 你
How It Works
One handler. Log type and data for each event.
Start opens the session. Often with empty or early data.
Update tracks candidates. May fire many times.
End closes the session. Final committed text is usually in data / the field value.
Compatibility
Browser Support
Element.compositionend is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Element compositionend
Fires when an IME (or similar) completes or cancels a composition session.
WidelyAvailable
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported (legacy)
Supported
compositionendBaseline support
Bottom line: Safe everywhere modern. Clear composing state on compositionend, then run final UI logic. Avoid CompositionEvent.locale. See the MDN Element compositionend reference.
Frequently Asked Questions
It fires when a text composition system such as an Input Method Editor (IME) completes or cancels the current composition session — for example after finishing a Chinese character with a Pinyin IME (MDN).
No. MDN marks Element compositionend as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. (CompositionEvent.locale is separately Deprecated and Non-standard — avoid it.)
A CompositionEvent (inherits from UIEvent). The useful property for most apps is data — the characters generated for this event.
compositionstart begins a session, compositionupdate fires as the candidate text changes, and compositionend fires when the session completes or is canceled.
Switch to a CJK (or other IME) keyboard layout. Shortcuts vary by OS (for example Win + . on Windows for emoji/IME UI, or Option + ` on some macOS setups).
Often yes for custom editors. During composition, InputEvent.isComposing may be true. Wait for compositionend before treating text as final committed characters.