JavaScript MouseEvent mozInputSource Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Non-standard
Instance property

What You’ll Learn

MouseEvent.mozInputSource is a non-standard read-only number that reports the kind of input device that created the mouse event. Learn the MOZ_SOURCE_* values, why device type matters for accuracy, how to feature-detect safely, and how Pointer Events replace it.

01

Kind

Instance property

02

Returns

Number (0–6)

03

Status

Non-standard

04

Access

event.mozInputSource

05

Engine

Firefox-oriented

06

Prefer

pointerType

Introduction

Not every “mouse” event comes from a physical mouse. Touch screens, pens, and even keyboards can produce mouse-like events. Firefox exposes mozInputSource so you can tell which device was involved—handy when touch coordinates need larger hit targets than a precise mouse.

JavaScript
element.addEventListener("mousedown", (event) => {
  console.log(event.mozInputSource); // number in Firefox; often undefined elsewhere
});
💡
Beginner tip

Treat mozInputSource as Firefox legacy reading material. For new code, listen to pointerdown / pointermove and read event.pointerType instead.

Understanding the Property

MDN: MouseEvent.mozInputSource provides information indicating the type of device that generated the event. That lets you, for example, decide whether coordinates came from an actual mouse or from a touch event (which can affect how accurately you interpret those coordinates).

  • Instance — read event.mozInputSource in a handler.
  • Number — one of the MOZ_SOURCE_* values (0–6).
  • Non-standard — not in any official specification.
  • Firefox-first — usually missing in Chromium and Safari.

📝 Syntax

JavaScript
const source = mouseEvent.mozInputSource;

Value

A number describing the input device when the property is supported; otherwise the property is typically undefined.

Safe read with fallback

JavaScript
function getInputKind(event) {
  if (typeof event.mozInputSource === "number") {
    return event.mozInputSource; // Firefox / non-standard
  }
  if (typeof event.pointerType === "string" && event.pointerType) {
    return event.pointerType; // standard Pointer Events
  }
  return "unknown";
}

📚 MOZ_SOURCE_* Values

MDN documents these constants and numeric values. In Firefox they may also appear as MouseEvent.MOZ_SOURCE_MOUSE, MouseEvent.MOZ_SOURCE_TOUCH, and so on.

ConstantValueMeaning
MOZ_SOURCE_UNKNOWN0Input device is unknown
MOZ_SOURCE_MOUSE1Mouse or mouse-like device
MOZ_SOURCE_PEN2Pen on a tablet
MOZ_SOURCE_ERASER3Eraser on a tablet
MOZ_SOURCE_CURSOR4Cursor-generated event
MOZ_SOURCE_TOUCH5Touch interface
MOZ_SOURCE_KEYBOARD6Keyboard-generated event

⚖️ mozInputSource vs pointerType

APIStatusTypical values
event.mozInputSourceNon-standardNumbers 0–6 (Firefox)
event.pointerTypeStandard"mouse", "pen", "touch"

Use Pointer Events for new apps. Keep mozInputSource only when you must understand or maintain older Firefox-specific code.

⚡ Quick Reference

GoalCode
Read (if present)event.mozInputSource
Feature-detecttypeof event.mozInputSource === "number"
Compare to mouseevent.mozInputSource === 1 (or MOZ_SOURCE_MOUSE)
Compare to touchevent.mozInputSource === 5 (or MOZ_SOURCE_TOUCH)
Modern alternativeevent.pointerType on PointerEvent
MDN statusNon-standard (not in any spec)

🔍 At a Glance

Four facts about mozInputSource.

Kind
instance

On the event

Type
number

0–6 when set

Status
non-std

Not in any spec

Prefer
pointerType

Pointer Events

Examples Gallery

Examples follow MDN MouseEvent.mozInputSource. Best results are in Firefox. Other browsers usually show undefined—that is expected for a non-standard API.

📚 Getting Started

Read mozInputSource from real pointer events.

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

In Firefox a normal mouse click often reports 1 (MOZ_SOURCE_MOUSE). Elsewhere you may see the string undefined because the property does not exist.

Example 2 — Map Numbers to Friendly Labels

Turn MDN’s numeric codes into readable device names.

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

document.addEventListener("click", (e) => {
  const code = e.mozInputSource;
  const label = LABELS[code] || String(code);
  console.log(code, label);
});
Try It Yourself

How It Works

A small lookup table mirrors MDN’s constant table so beginners can read mouse or touch instead of raw numbers.

📈 Detection & Modern Alternatives

Feature-detect safely and migrate toward Pointer Events.

Example 3 — Feature-Detect Before Using

Never assume every browser exposes Mozilla-only properties.

JavaScript
document.addEventListener("click", (e) => {
  if (typeof e.mozInputSource !== "number") {
    console.log("mozInputSource not supported in this browser");
    return;
  }
  console.log("Supported. Source code:", e.mozInputSource);
});
Try It Yourself

How It Works

Checking typeof … === "number" avoids treating undefined as a valid device code.

Example 4 — Branch for Touch Accuracy

MDN’s idea: treat touch-sourced events differently from mouse events.

JavaScript
const MOZ_SOURCE_TOUCH = 5;
const MOZ_SOURCE_MOUSE = 1;

box.addEventListener("mousedown", (e) => {
  if (typeof e.mozInputSource !== "number") {
    console.log("Use pointerType instead on this browser");
    return;
  }
  if (e.mozInputSource === MOZ_SOURCE_TOUCH) {
    console.log("Touch source — prefer larger hit targets");
  } else if (e.mozInputSource === MOZ_SOURCE_MOUSE) {
    console.log("Mouse source — fine-grained coordinates OK");
  } else {
    console.log("Other source:", e.mozInputSource);
  }
});
Try It Yourself

How It Works

Comparing against 5 / 1 (or the named constants when available) lets Firefox-only code adjust UX for touch vs mouse.

Example 5 — Prefer pointerType (Standard)

The modern, cross-browser way to learn the device kind.

JavaScript
target.addEventListener("pointerdown", (e) => {
  // Standard: "mouse" | "pen" | "touch" | ""
  console.log("pointerType:", e.pointerType);

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

How It Works

pointerType is the supported replacement. Keep mozInputSource only as an optional Firefox detail while you migrate.

🚀 Common Use Cases

  • Reading Firefox-only device type while debugging legacy code.
  • Understanding why touch vs mouse accuracy might differ (MDN use case).
  • Comparing Mozilla constants with modern pointerType strings.
  • Teaching non-standard APIs and why feature detection matters.
  • Migrating old Firefox scripts toward Pointer Events.

🔧 How It Works

1

Device generates input

Mouse, pen, touch, keyboard, or another source interacts with the page.

Input
2

Firefox builds MouseEvent

Sets non-standard mozInputSource to a MOZ_SOURCE_* number.

Event
3

Listener receives the event

Your click / mousedown handler runs.

Handler
4

Branch on device kind

Adjust accuracy / UX—or prefer pointerType instead.

📝 Notes

  • MDN: Non-standard; not part of any specification.
  • Not labeled Deprecated or Experimental on the MDN page—but still unsafe for production cross-browser use.
  • Primarily a Firefox / Gecko extension; often undefined elsewhere.
  • Prefer PointerEvent.pointerType for new code.
  • Related: movementY, movementX, button, MouseEvent(), Window, JavaScript hub.

Limited / Non-standard Support

MouseEvent.mozInputSource is a Non-standard Mozilla property. Logos use the shared browser-image-sprite.png sprite from this project. Expect Firefox-oriented support; do not require it for production UX.

Non-standard · Firefox-oriented

MouseEvent.mozInputSource

Firefox input-device code. Feature-detect; prefer PointerEvent.pointerType for new apps.

Limited Non-standard
Google Chrome Not supported (property usually undefined)
No support
Mozilla Firefox Supported · Non-standard Gecko property
Supported
Apple Safari Not supported (property usually undefined)
No support
Microsoft Edge Not supported (Chromium)
No support
Opera Not supported (Chromium)
No support
Internet Explorer Not a modern target for this API
No support
mozInputSource Limited

Bottom line: Non-standard device-source number; use pointerType for cross-browser input detection.

Conclusion

event.mozInputSource is a non-standard Firefox number that names the device behind a mouse event—mouse, pen, touch, keyboard, and more. Learn it for legacy Gecko code, then ship with PointerEvent.pointerType instead.

Continue with movementY, offsetX, button, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before reading mozInputSource
  • Prefer pointerType on Pointer Events for new code
  • Map numeric codes to labels while learning
  • Document why legacy Firefox code still uses it
  • Test touch vs mouse UX with larger hit targets when needed

❌ Don’t

  • Ship production UX that requires mozInputSource
  • Assume Chromium or Safari expose the property
  • Skip fallbacks when the value is missing
  • Confuse it with standard pointerType
  • Treat non-standard APIs as future-proof

Key Takeaways

Knowledge Unlocked

Five things to remember about mozInputSource

Non-standard Firefox device-source number—learn it, prefer standards.

5
Core concepts
🔢 02

Number

0–6 codes

Type
⚠️ 03

Non-standard

not in any spec

Status
🤖 04

Firefox

Gecko-oriented

Engine
💡 05

pointerType

prefer this

Modern

❓ Frequently Asked Questions

It is a non-standard, read-only number on MouseEvent (mainly Firefox) that describes which kind of device generated the 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 on that MDN page, 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 and is the supported way to tell devices apart.
Touch and pen coordinates can be less precise than a mouse. Knowing the device helps you adjust hit targets, ignore 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.
Did you know?

MDN highlights a practical reason this property existed: touch-generated mouse events can be less precise than real mouse events. Knowing the source helped Firefox apps adjust how they trusted coordinates—today that job belongs to PointerEvent.pointerType across browsers.

Next: MouseEvent.offsetX

Learn element-local X coordinates from the target padding edge.

offsetX →

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