JavaScript Element compositionstart Event

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

What You’ll Learn

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

01

Kind

Instance event

02

Type

CompositionEvent

03

When

IME session starts

04

Handler

oncompositionstart

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. compositionstart 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 compositionstart, mark your UI as composing (pause live search, show a hint). Wait for compositionend before treating text as final.

Understanding compositionstart

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("compositionstart", (event) => { });

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

Event type
CompositionEvent

data + locale

Means
IME start

Session begins

Pair with
start/update

Full session

Baseline
yes

Widely available

Examples Gallery

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

📚 Getting Started

Log when an IME composition session begins (MDN style).

Example 1 — addEventListener("compositionstart")

MDN idea: print data when the IME session starts.

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

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

How It Works

Without an active IME, this listener may stay quiet. At session start, event.data is often empty or holds the initial composing characters.

Example 2 — oncompositionstart Property

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

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

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

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

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Log, Flag & Pause

Log the full IME trio, set a composing flag, and pause live search.

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

The first line is the session beginning. Updates show intermediate text; end commits or cancels.

Example 4 — Set a Composing Flag

Flip UI state on start; clear it on end.

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

field.addEventListener("compositionstart", () => {
  composing = true;
  status.textContent = "Composing…";
});

field.addEventListener("compositionend", () => {
  composing = false;
  status.textContent = "Ready (value: " + field.value + ")";
});
Try It Yourself

How It Works

A boolean flag (or CSS class) lets the rest of your app know not to treat partial IME text as a finished string.

Example 5 — Pause Search on Start

Stop live search when composition begins; resume after compositionend.

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

field.addEventListener("compositionstart", () => {
  composing = true;
  out.textContent = "(composing… search paused)";
});

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

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

How It Works

Starting the pause on compositionstart is clearer than only inspecting isComposing on every input—use both if you want.

🚀 Common Use Cases

  • Showing a “composing…” status when an IME session begins.
  • Pausing live search or autosave until composition ends.
  • Building custom editors that respect IME session boundaries.
  • Logging IME session starts for internationalization debugging.
  • Pairing with compositionupdate / compositionend for the full story.

🔧 How It Works

1

compositionstart fires

IME begins a new composition session on the focused control.

Start
2

Candidates update

compositionupdate fires as composing text changes.

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

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

Works across modern desktop and mobile browsers when an IME composition session begins.

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

Bottom line: Listen for compositionstart to mark composing UI; pair with update/end for the full IME session.

Conclusion

compositionstart is the “IME session began” signal. Set composing state, pause live logic that needs final text, then wait for compositionend to resume.

Continue with compositionupdate, compositionend, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer addEventListener("compositionstart", ...)
  • Pause search/validation when composition starts
  • Log start/update/end together while debugging
  • Clear composing UI on compositionend
  • Test with a real IME keyboard layout

❌ Don’t

  • Assume composition events fire for plain Latin typing
  • Treat text as final as soon as composition starts
  • Forget to clear composing flags when the session ends
  • Confuse composition with the everyday input event
  • Overwrite oncompositionstart if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about compositionstart

IME session began—mark composing, then wait for end.

5
Core concepts
📄 02

CompositionEvent

data + locale

API
🔁 03

Before update

start of session

Order
🔎 04

Pause 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) starts a new composition session — for example when a user begins entering a Chinese character with a Pinyin IME.
No. MDN marks Element compositionstart 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, 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.
Mark your UI as composing: pause live search, avoid treating partial IME text as final, and wait for compositionend (or input with isComposing false) before committing logic.
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: compositionupdate

Learn what fires as IME composing text changes.

compositionupdate →

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