In JavaScript, the beforeinput event fires when the value of an <input> or <textarea> is about to be modified (MDN). Unlike input, it does not fire on <select>. It also applies to contenteditable and designMode.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for beforeinput. Start with this line.
JavaScript
el.addEventListener("beforeinput", fn)
Call
What it does
el.addEventListener("beforeinput", fn)
Primary signature.
Built into the browser. Listen with el.addEventListener("beforeinput", …) — no import required.
Library declarations
JavaScript
el.addEventListener("beforeinput", fn)
Parameters
Parameter
Description
Editable target
Required. input / textarea / editing host
preventDefault()
Optional. Block cancelable edits only
Return Value
Return Value
Description
*
Fires as an Element event (listener receives the Event object).
JavaScript Examples
Example 1 — Log Value Before Edit (MDN)
Show the current value immediately before the browser applies the change.
Call preventDefault() when the event is cancelable.
Remember MDN’s warning: autofill / IME may still change the value — pair with input if needed.
Compatibility
Browser Support
Element.beforeinput is marked Baseline Widely available on MDN (since March 2021). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Element beforeinput
Fires before an editable value changes — InputEvent with data and inputType.
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 ExplorerNot supported
Not supported
beforeinputBaseline support
Bottom line: Safe for modern browsers. Use beforeinput to inspect or cancel cancelable edits, and pair with input for complete coverage. See the MDN Element beforeinput reference.
Frequently Asked Questions
It fires when the value of an input or textarea is about to be modified (MDN). Unlike the input event, it does not fire on select. It also applies to contenteditable elements and when document.designMode is on.
No. MDN marks Element beforeinput as Baseline Widely available (since March 2021). It is not Deprecated, Experimental, or Non-standard.
An InputEvent (inherits from UIEvent). Useful properties include data, dataTransfer, inputType, and isComposing.
Often yes for ordinary typing, which lets you override edit behavior before the DOM changes. But not every modification is cancelable — autocomplete, spell-check corrections, password autofill, and some IME updates may fire a non-cancelable event or skip beforeinput (MDN). Also handle input and revert unwanted changes when needed.
beforeinput fires before the value changes (when cancelable). input fires after the value has already changed. beforeinput does not fire on <select>; input can.
A common check is: window.InputEvent && typeof InputEvent.prototype.getTargetRanges === "function". That signals modern beforeinput / getTargetRanges support (MDN).