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.
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.
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.
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:
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.
You run a legacy desktop site and want to redirect mobile users to /mobile.
is-mobileimport isMobile from 'is-mobile';
if (isMobile() && !window.location.pathname.startsWith('/mobile')) {
window.location.href = '/mobile';
}
Your app shows a compact layout on phones but a split view on tablets.
mobile-detect or ua-parser-js// With mobile-detect
const md = new MobileDetect(navigator.userAgent);
const layout = md.tablet() ? 'split' : md.phone() ? 'compact' : 'desktop';
You’re using Next.js and want to pre-render different content based on device.
ua-parser-js// 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 } };
}
You want to enable a touch-friendly carousel only on mobile.
mobile-device-detectisMobile.import { isMobile } from 'mobile-device-detect';
function App() {
return isMobile ? <TouchCarousel /> : <DesktopCarousel />;
}
But caution: this breaks in SSR unless handled carefully.
| Package | Output Type | Custom UA Support | SSR Safe | Granularity | Maintenance Status |
|---|---|---|---|---|---|
is-mobile | Boolean | ✅ | ✅ | Mobile / Not | Stable |
mobile-detect | Strings / Null | ✅ | ✅ | Phone, Tablet, OS | Low activity |
mobile-device-detect | Boolean constants | ❌ | ❌* | Device + OS flags | Unmaintained |
ua-parser-js | Full object | ✅ | ✅ | Full device/browser/os | Actively maintained |
* Can be made SSR-safe with build-time replacements, but not out of the box.
is-mobile.mobile-detect works, but verify it covers your target devices.ua-parser-js is the professional choice.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.
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.
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.
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.
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.
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).
version 1.x : https://github.com/faisalman/ua-parser-js/tree/1.0.x#documentationversion 2.x : https://docs.uaparser.devBefore upgrading from v0.7 / v1.0, please read CHANGELOG to
see what's new & breaking.
| Open-Source Editions | PRO / Commercial Editions | ||||
|---|---|---|---|---|---|
| License options | MIT (v1.x) | AGPL (v2.x) | PRO Personal | PRO Business | PRO 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 | ✅ | ✅ | ✅ | ✅ | ✅ |
| Price | FREE* (License) | FREE* (License) | $14 (License) | $29 (License) | $599 (License) |
GET THE PRO PACKAGES 📥 | |||||
Please read CONTRIBUTING guide first for the instruction details.
Made with contributors-img.
Support the open-source editions of UAParser.js through one of the following options: