JavaScript Element compositionend Event

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

What You’ll Learn

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

01

Kind

Instance event

02

Type

CompositionEvent

03

When

IME session ends

04

Handler

oncompositionend

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. compositionend means the session finished—either the text was committed or the composition was canceled. MDN’s classic example is finishing a Chinese character with a Pinyin IME.

💡
Beginner tip

During composition, treat intermediate text as temporary. Use compositionend (and/or input with isComposing === false) when you need the final committed characters.

Understanding compositionend

An instance event that answers: “Did the IME composition session just finish or get canceled?”

  • Fires when composition completes or is canceled.
  • CompositionEvent — read data (and sometimes locale).
  • Siblingscompositionstart, compositionupdate.
  • Useful for custom editors, search-as-you-type, and validation after IME commit.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

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

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

oncompositionend = (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("compositionend", fn)
Handler propertyel.oncompositionend = 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 compositionend.

Event type
CompositionEvent

data + locale

Means
IME done

Complete or cancel

Pair with
start/update

Full session

Baseline
yes

Widely available

Examples Gallery

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

📚 Getting Started

Log generated characters when composition ends (MDN style).

Example 1 — addEventListener("compositionend")

MDN idea: print the characters produced when the IME session finishes.

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

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

How It Works

Without an active IME, this listener may stay quiet. With IME commit, event.data holds the generated string for that end event.

Example 2 — oncompositionend Property

Same end-of-session hook using the handler property.

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

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

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

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Log, Commit & Detect

Log the full IME trio, react to committed data, and watch isComposing.

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

Updates show intermediate composing text; the end line is the final (or empty if canceled).

Example 4 — Act on Committed data

Update a status line only when composition ends with non-empty data.

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

field.addEventListener("compositionend", (event) => {
  if (event.data) {
    status.textContent = "Committed: " + event.data;
  } else {
    status.textContent = "Composition canceled or empty";
  }
});
Try It Yourself

How It Works

Empty data can mean cancel or an end event that did not produce characters. Always combine with the field value when needed.

Example 5 — Skip Intermediate input During IME

Ignore input while composing; handle final text on compositionend.

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

field.addEventListener("input", (event) => {
  if (event.isComposing) {
    out.textContent = "(composing… skip search)";
    return;
  }
  out.textContent = "Search for: " + field.value;
});

field.addEventListener("compositionend", () => {
  out.textContent = "Search for: " + field.value;
});
Try It Yourself

How It Works

This pattern reduces noisy search requests while the user is still picking IME candidates.

🚀 Common Use Cases

  • Running search or validation only after IME commit.
  • Building custom rich-text / contenteditable editors that respect composition.
  • Logging IME sessions for debugging international input.
  • Syncing UI hints (“composing…”) until composition ends.
  • Pairing with beforeinput / input for complete edit stories.

🔧 How It Works

1

User opens an IME session

compositionstart marks the beginning.

Start
2

Candidates update

compositionupdate fires as composing text changes.

Update
3

User commits or cancels

IME finishes the session.

Decide
4

compositionend fires

Read event.data and treat text as finalized for this session.

📝 Notes

  • MDN: Baseline Widely available (since July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Related events: compositionstart, compositionupdate.
  • Latin-only typing may never fire composition events—test with a real IME.
  • Related learning: compositionstart, beforeinput, addEventListener(), JavaScript hub.

Universal Browser Support

compositionend 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 compositionend

Works across modern desktop and mobile browsers for IME composition session completion.

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
compositionend Baseline

Bottom line: Listen for compositionend when you need the final IME-committed characters; pair with start/update for the full session.

Conclusion

compositionend is the “IME session finished” signal. Read event.data, pair it with start/update when debugging, and avoid treating intermediate composing text as final user input.

Continue with compositionstart, beforeinput, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener("compositionend", ...)
  • Defer search/validation until composition ends when using IMEs
  • Log start/update/end together while debugging
  • Check event.data and the control value
  • Test with a real IME keyboard layout

❌ Don’t

  • Assume composition events fire for plain Latin typing
  • Treat every input during IME as final text
  • Ignore cancel paths (empty or unexpected data)
  • Confuse composition with the everyday input event
  • Overwrite oncompositionend if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about compositionend

IME session finished—read data, then treat text as committed.

5
Core concepts
📄 02

CompositionEvent

data + locale

API
🔁 03

After update

end of session

Order
🔎 04

Skip mid-IME

search later

Pattern
🎯 05

Baseline

widely available

Compat

❓ 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.
No. MDN marks Element compositionend 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) and locale (input method locale).
compositionstart begins a session, compositionupdate fires as the candidate text changes, 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.
Often yes for custom editors. During composition, InputEvent.isComposing may be true. Wait for compositionend before treating text as final committed characters.
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: compositionstart

Learn the event that fires when an IME composition session begins.

compositionstart →

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