JavaScript MouseEvent mozInputSource Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

MouseEvent.mozInputSource is a read-only number (Firefox) that tells you which kind of device generated the event — mouse, pen, touch, keyboard, and a few others.

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use event.mozInputSource. Start with this line.

JavaScript
event.mozInputSource
CallWhat it does
event.mozInputSourcePrimary signature.

Built into the browser. Read event.mozInputSource on a MouseEvent — no import required.

Library declarations
JavaScript
event.mozInputSource

Parameters

ParameterDescription
Mouse / pointer eventRequired. Source of the property
Feature detectRequired. Avoid reading undefined as a real code

Return Value

Return ValueDescription
*The current value of event.mozInputSource.

JavaScript Examples

Example 1 — Log mozInputSource on Click

Print the raw numeric source after each click.

JavaScript
const log = document.querySelector("#log");

document.addEventListener("click", (e) => {
  log.textContent = `mozInputSource: ${e.mozInputSource}`;
});
Try It Yourself

How It Works

  1. Find the log node. querySelector("#log") holds the result text.
  2. Listen for clicks. Each click delivers a MouseEvent.
  3. Read the property. Firefox often reports 1 for a mouse; other browsers may print undefined.
  4. Update the UI. The template string writes the value into the log.

Example 2 — Feature-Detect and Label the Source

Never treat undefined as a real device code.

JavaScript
const labels = {
  0: "unknown", 1: "mouse", 2: "pen", 3: "eraser",
  4: "cursor", 5: "touch", 6: "keyboard"
};

document.addEventListener("click", (e) => {
  if (typeof e.mozInputSource !== "number") {
    console.log("mozInputSource not supported");
    return;
  }
  console.log(labels[e.mozInputSource] || "other");
});
Try It Yourself

How It Works

  1. Build a label map from MDN’s 0–6 constants.
  2. Feature-detect. Only continue when the value is a number.
  3. Look up the label. 1 → "mouse", 5 → "touch", and so on.
  4. Exit early elsewhere. Unsupported browsers skip the map and log a clear message.

Example 3 — Prefer pointerType (Standard)

The modern, cross-browser way to tell mouse / pen / touch apart.

JavaScript
document.addEventListener("pointerdown", (e) => {
  // Standard across modern browsers
  console.log(e.pointerType); // "mouse" | "pen" | "touch"

  // Optional Firefox-only detail
  if (typeof e.mozInputSource === "number") {
    console.log("moz:", e.mozInputSource);
  }
});
Try It Yourself

How It Works

  1. Listen for pointerdown. Pointer Events unify mouse, pen, and touch.
  2. Read pointerType. You get a clear string: "mouse", "pen", or "touch".
  3. Optionally read moz. Only if the number exists — never required for the main branch.
  4. Production tip. Build product logic on pointerType; treat mozInputSource as Firefox bonus detail.

Browser Support

MouseEvent.mozInputSource is Non-standard and mainly available in Firefox. Other engines typically omit it. Prefer PointerEvent.pointerType for production.

✓ Non-standard · Firefox

MouseEvent.mozInputSource

Mozilla-specific device-source number — useful for learning and Firefox-only debugging, not for cross-browser product logic.

Limited Firefox-focused
Mozilla Firefox Supported · Gecko
Supported
Google Chrome Not supported · Usually undefined
No support
Apple Safari Not supported · Usually undefined
No support
Microsoft Edge Not supported · Usually undefined
No support
Opera Not supported · Chromium-based
No support
Internet Explorer Not supported
No support
mozInputSource Limited

Bottom line: Feature-detect before use. For mouse vs pen vs touch in real apps, use standard Pointer Events (pointerType).

Frequently Asked Questions

It is a non-standard, read-only number (mainly Firefox) that describes which kind of device generated the mouse event—for example a real mouse, a tablet pen, a touch screen, or a keyboard.
MDN marks it Non-standard — not part of any specification. It is not labeled Deprecated or Experimental, but you should not rely on it in production cross-browser code.
MDN lists: 0 unknown, 1 mouse, 2 pen, 3 eraser, 4 cursor, 5 touch, 6 keyboard. In Firefox these match MouseEvent.MOZ_SOURCE_* constants when available.
Prefer the standard Pointer Events API: PointerEvent.pointerType returns "mouse", "pen", or "touch". It works across modern browsers.
Touch and pen coordinates can be less precise than a mouse. Knowing the device helps you adjust hit targets, skip hover-only UI on touch, or change accuracy assumptions.
No. It is a Mozilla-specific extension. In Chrome, Safari, and Edge the property is usually undefined. Always feature-detect before reading it.

Next: MouseEvent.offsetX

Learn the X coordinate relative to the padding edge of the target element.

offsetX tutorial →

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.

11 people found this page helpful