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 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.
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.
Check if mobile browser, based on useragent string.
var mobile = require('is-mobile');
console.log(mobile());
// => false
Returns true if a mobile browser is being used.
If you don't specify opts.ua it will use navigator.userAgent.
To add support for tablets, set tablet: true.
To enable feature detection (i.e. namely for iPad with iOS 13), set featureDetect: true and tablet: true. This will only work in browser environments.
opts.ua can also be an instance of a node.js http request, in which
case it will read the user agent header.
Example:
var http = require('http');
var mobile = require('is-mobile');
var server = http.createServer(function (req, res) {
res.end(mobile({ ua: req }));
});
server.listen(8000);
With npm do:
npm install is-mobile
Bundle for the browser with browserify.
Taken from detectmobilebrowsers.com.
Armv7l support added by @antongolub.
(MIT)
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.