ua-parser-js vs is-mobile vs mobile-detect vs mobile-device-detect
JavaScript Libraries for Mobile Device Detection
ua-parser-jsis-mobilemobile-detectmobile-device-detectSimilar Packages:
JavaScript Libraries for Mobile Device Detection

is-mobile, mobile-detect, mobile-device-detect, and ua-parser-js are JavaScript libraries designed to detect mobile devices by analyzing the browser's User-Agent string. They help developers apply device-specific logic for responsive design, performance optimization, or user experience customization. is-mobile provides a simple boolean check, mobile-detect offers detailed device categorization (phone vs. tablet, OS type), mobile-device-detect exports pre-evaluated boolean flags for common device types, and ua-parser-js delivers comprehensive parsing of the entire User-Agent into structured device, browser, and OS information.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
ua-parser-js18,675,74010,017479 kB23a day agoAGPL-3.0-or-later
is-mobile1,040,5242519.29 kB2a year agoMIT
mobile-detect206,4054,146-135 years agoMIT
mobile-device-detect22,667199-236 years agoMIT

Detecting Mobile Devices in JavaScript: A Practical Guide

When building responsive web applications, you sometimes need to detect whether a user is on a mobile device — not just based on screen size, but actual device type. This matters for things like touch interfaces, performance tuning, or redirecting to a mobile-optimized experience. The packages is-mobile, mobile-detect, mobile-device-detect, and ua-parser-js all aim to solve this, but with very different approaches, trade-offs, and levels of control.

📱 Detection Strategy: Simple Boolean vs Full Device Intelligence

is-mobile gives you a simple yes/no answer: is this a mobile device?

import isMobile from 'is-mobile';

// Basic usage
if (isMobile()) {
  // Apply mobile-specific logic
}

// You can also pass a custom User-Agent string
const ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) ...';
if (isMobile({ ua })) {
  // ...
}

It’s lightweight and opinionated: if the UA matches known mobile patterns (iOS, Android, etc.), it returns true. No details — just a boolean.

mobile-detect offers more granularity: it tells you what kind of mobile device you’re dealing with.

import MobileDetect from 'mobile-detect';

const md = new MobileDetect(window.navigator.userAgent);

console.log(md.mobile());        // 'iPhone', 'Android', etc., or null
console.log(md.phone());         // 'iPhone' if it's a phone
console.log(md.tablet());        // 'iPad' if it's a tablet
console.log(md.os());            // 'iOS', 'Android', etc.

This is useful when your logic differs between phones and tablets, or you need to know the OS.

mobile-device-detect takes an even simpler route: it exports ready-to-use boolean flags.

import { isMobile, isTablet, isIOS, isAndroid } from 'mobile-device-detect';

if (isMobile) {
  // True for any mobile device
}

if (isIOS && isTablet) {
  // Specifically an iPad
}

No instantiation, no methods — just constants evaluated once at load time. Great for quick checks, but inflexible if you need to test arbitrary User-Agent strings (e.g., in server-side rendering or testing).

ua-parser-js doesn’t focus solely on mobile — it parses the entire User-Agent into structured data.

import UAParser from 'ua-parser-js';

const parser = new UAParser();
const result = parser.getResult();

console.log(result.device.type);   // 'mobile', 'tablet', 'console', etc.
console.log(result.os.name);       // 'iOS', 'Android'
console.log(result.browser.name);  // 'Chrome', 'Safari'

You can then decide what “mobile” means in your app. Maybe you treat tablets differently than phones — ua-parser-js gives you the raw data to make that call.

⚙️ Flexibility: Runtime Checks vs Static Constants

Only is-mobile, mobile-detect, and ua-parser-js let you analyze arbitrary User-Agent strings. This is critical if you're doing detection on the server (e.g., in Next.js getServerSideProps) or writing tests.

// Server-side example with ua-parser-js
export async function getServerSideProps({ req }) {
  const ua = req.headers['user-agent'];
  const parser = new UAParser(ua);
  const isMobile = parser.getDevice().type === 'mobile';
  return { props: { isMobile } };
}

In contrast, mobile-device-detect reads navigator.userAgent only once when the module loads. That means:

  • It won’t work in Node.js environments without a polyfill.
  • You can’t test different device scenarios in the same runtime.
  • It’s not suitable for SSR unless you replace the module during build (e.g., via Webpack aliases).

🧪 Accuracy and Maintenance

All four packages rely on User-Agent parsing, which is inherently fragile — browsers can spoof UAs, and new devices appear constantly. However, their maintenance status differs.

  • ua-parser-js is actively maintained and uses a regularly updated regex pattern set (mirroring the widely used UAParser community project). It’s the most future-proof choice.
  • mobile-detect hasn’t seen significant updates in years, and its regex patterns may miss newer devices.
  • is-mobile is minimal and stable, but its detection logic is hardcoded and not easily extensible.
  • mobile-device-detect appears unmaintained; its last meaningful update was several years ago, and it lacks support for many modern device patterns.

⚠️ Important: None of these should be your only method for responsive design. Always combine UA detection with feature detection (e.g., matchMedia('(max-width: 768px)')) and progressive enhancement.

🧩 Real-World Use Cases

Case 1: Lightweight Mobile Redirect

You run a legacy desktop site and want to redirect mobile users to /mobile.

  • Best choice: is-mobile
  • Why? You only need a boolean, and every byte counts on the landing page.
import isMobile from 'is-mobile';
if (isMobile() && !window.location.pathname.startsWith('/mobile')) {
  window.location.href = '/mobile';
}

Case 2: Adaptive UI Based on Device Type

Your app shows a compact layout on phones but a split view on tablets.

  • Best choice: mobile-detect or ua-parser-js
  • Why? You need to distinguish phones from tablets.
// With mobile-detect
const md = new MobileDetect(navigator.userAgent);
const layout = md.tablet() ? 'split' : md.phone() ? 'compact' : 'desktop';

Case 3: Server-Side Rendering with Device-Specific Props

You’re using Next.js and want to pre-render different content based on device.

  • Best choice: ua-parser-js
  • Why? It works reliably in Node.js and gives full control.
// pages/index.js
export async function getServerSideProps({ req }) {
  const parser = new UAParser(req.headers['user-agent']);
  const deviceType = parser.getDevice().type || 'desktop';
  return { props: { deviceType } };
}

Case 4: Quick Client-Side Feature Toggle

You want to enable a touch-friendly carousel only on mobile.

  • Best choice: mobile-device-detect
  • Why? It’s zero-config and tree-shakable if you only import isMobile.
import { isMobile } from 'mobile-device-detect';

function App() {
  return isMobile ? <TouchCarousel /> : <DesktopCarousel />;
}

But caution: this breaks in SSR unless handled carefully.

🔍 Summary Table

PackageOutput TypeCustom UA SupportSSR SafeGranularityMaintenance Status
is-mobileBooleanMobile / NotStable
mobile-detectStrings / NullPhone, Tablet, OSLow activity
mobile-device-detectBoolean constants❌*Device + OS flagsUnmaintained
ua-parser-jsFull objectFull device/browser/osActively maintained

* Can be made SSR-safe with build-time replacements, but not out of the box.

💡 Final Recommendation

  • If you only need a true/false for “is this mobile?” and care about bundle size → use is-mobile.
  • If you need to distinguish phones from tablets and are okay with a slightly larger footprint → mobile-detect works, but verify it covers your target devices.
  • If you’re doing server-side rendering or need maximum accuracy and future-proofingua-parser-js is the professional choice.
  • Avoid mobile-device-detect in new projects — its lack of custom UA support and apparent abandonment make it risky for production use beyond trivial cases.

Remember: User-Agent sniffing is a fallback. Whenever possible, prefer CSS media queries, touch event detection ('ontouchstart' in window), or pointer media features (@media (pointer: coarse)). But when you do need UA-based logic, choose the right tool for your precision, environment, and maintenance needs.

How to Choose: ua-parser-js vs is-mobile vs mobile-detect vs mobile-device-detect
  • ua-parser-js:

    Choose ua-parser-js when you need robust, accurate, and future-proof device detection—especially in server-rendered applications or when full control over parsing logic is required. It provides complete breakdowns of device type, browser, and OS, and is actively maintained with up-to-date detection patterns, making it the most reliable choice for professional applications.

  • is-mobile:

    Choose is-mobile when you need a minimal, zero-configuration solution that returns a simple boolean indicating whether the current device is mobile. It’s ideal for lightweight client-side redirects or basic feature toggles where bundle size matters and you don’t need to distinguish between phones, tablets, or specific operating systems.

  • mobile-detect:

    Choose mobile-detect when you require more granular device information—such as distinguishing phones from tablets or identifying the OS—but still want a straightforward API. It’s suitable for client-side adaptive UIs, though verify its detection rules cover your target devices, as updates have been infrequent.

  • mobile-device-detect:

    Avoid mobile-device-detect in new projects. While convenient for quick client-side checks with precomputed booleans like isIOS or isTablet, it cannot analyze arbitrary User-Agent strings, making it incompatible with server-side rendering and testing scenarios. Its apparent lack of active maintenance raises reliability concerns for production use.

README for ua-parser-js

Featured Sponsors

https://ref.wisprflow.ai/Rxj3n8H


https://uaparser.dev https://uaparser.dev https://uaparser.dev https://uaparser.dev

Discord invite

UAParser.js

The most comprehensive, compact, and up-to-date JavaScript library to detect user's browser, OS, CPU, and device type/model. Also detect bots, apps, and more. Runs seamlessly in the browser (client-side) or Node.js (server-side).

Demo

Documentation

Before upgrading from v0.7 / v1.0, please read CHANGELOG to see what's new & breaking.

Package & Pricing

Open-Source EditionsPRO / Commercial Editions
License optionsMIT (v1.x)AGPL (v2.x)PRO PersonalPRO BusinessPRO Enterprise
Browser Detection⚠️
CPU Detection⚠️
Device Detection⚠️
Rendering Engine Detection⚠️
OS detection⚠️
Enhanced+ Accuracy
Bot Detection
AI Detection
Extra Detections (Apps, Libs, Emails, Media Players, Crawlers, and more)
Client Hints Support
CommonJS Support
ESM Support
TypeScript Definitions
npm Module Available
Direct Downloads Available
Commercial Use Allowed
Permissive (non-Copyleft) License
No Open-Source Obligations
Unlimited End-Products
Unlimited Deployments
1-year Product Support
Lifetime Updates
PriceFREE* (License)FREE* (License)$14 (License)$29 (License)$599 (License)

GET THE PRO PACKAGES 📥

Development

Contributors

Please read CONTRIBUTING guide first for the instruction details.

Made with contributors-img.

Backers & Sponsors

Support the open-source editions of UAParser.js through one of the following options:

OpenCollective GitHub Sponsors PayPal WeChat/Alipay