isMobile()
truewhen the current environment looks like a mobile or tablet device, based on a UA regex.
| Signature | (options?: DetectOptions) => boolean |
| Matches | iPhone, iPod, iPad, Android+Mobile, BlackBerry, webOS, Opera Mini, etc. |
| Tree-shakes to | ~600 bytes (regex weight) |
What it matches
A compiled regex of common mobile / tablet tokens — derived from detectmobilebrowsers.com and lightly modernized:
iPhone,iPod,iPadAndroid+MobileBlackBerry,webOS,Symbian,Maemo,Windows CE- Mobile-specific Firefox builds (
Mobile.+Firefox) Opera Mobi,Opera Mini- Many others — see
src/is-mobile.ts.
This is a heuristic, not a feature check
For breakpoint decisions, prefer:
window.matchMedia('(pointer: coarse)').matches; // touch-first device
window.matchMedia('(max-width: 768px)').matches; // narrow viewport
@media (max-width: 768px) { /* … */ }
@media (pointer: coarse) { /* … */ }
isMobile() is appropriate for analytics, server hints, and download-badge logic.
Examples
- Default
- SSR
- With browser family
- Conditional load
import { isMobile } from 'get-browser';
if (isMobile()) {
document.body.classList.add('is-mobile');
}
Express middleware
import { isMobile } from 'get-browser';
app.use((req, res, next) => {
res.locals.bodyClass = isMobile({ userAgent: req.get('user-agent') ?? '' })
? 'is-mobile'
: 'is-desktop';
next();
});
import { isMobile, isSafari, isChrome } from 'get-browser';
// Distinguish Safari iOS from desktop Safari — they're both 'safari' to
// detect(), but their layout / capability quirks differ.
const isMobileSafari = isSafari() && isMobile();
const isMobileChrome = isChrome() && isMobile();
import { isMobile } from 'get-browser';
if (isMobile()) {
// Defer the desktop-only chart library
const { default: HeavyChart } = await import('./heavy-chart');
// …
}
iPadOS limitation
iPadOS 13+ defaults to a Mac UA — we can only identify iPads that explicitly self-identify (Safari's Request Mobile Website mode, embedded WebViews, etc.). See the isSafari() notes for the full story.