Mobile User Agent Detection — iOS, Android, and Common Patterns
Detect iOS and Android devices from user agent strings. Includes UA patterns for iPhone, iPad, Android phones and tablets, WebView detection, and how iOS 13+ iPadOS changed...
Use the tool
User Agent Parser
Parse any User-Agent string into browser, OS, device, and engine. Or detect your own. Built on the maintained ua-parser-js dataset.
Mobile user agent detection is more complex than it looks — iPadOS 13+ removed “iPad” from the UA, Android tablets don’t always say “tablet,” and in-app WebViews add their own strings.
Use the User Agent Parser to parse any UA string and identify the device.
iOS device detection
// iPhone detection:
function isIPhone(ua = navigator.userAgent) {
return /iPhone/.test(ua);
}
// iPad detection — pre-iPadOS 13:
function isIPadOld(ua = navigator.userAgent) {
return /iPad/.test(ua);
}
// iPad detection — iPadOS 13+ sends macOS UA:
// "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)..."
function isIPad(ua = navigator.userAgent) {
return (
/iPad/.test(ua) ||
(/Macintosh/.test(ua) && navigator.maxTouchPoints > 1)
);
}
// Any iOS device:
function isIOS(ua = navigator.userAgent) {
return /iPhone|iPod/.test(ua) || isIPad(ua);
}
// Get iOS version:
function getIOSVersion(ua = navigator.userAgent) {
const match = ua.match(/OS (\d+)_(\d+)_?(\d+)? like Mac OS X/);
if (!match) return null;
return {
major: parseInt(match[1]),
minor: parseInt(match[2]),
patch: parseInt(match[3] || '0'),
};
}
getIOSVersion('Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X)')
// { major: 17, minor: 2, patch: 0 }
Android detection
// Any Android device:
function isAndroid(ua = navigator.userAgent) {
return /Android/.test(ua);
}
// Android phone vs tablet:
function isAndroidPhone(ua = navigator.userAgent) {
return /Android/.test(ua) && /Mobile/.test(ua);
}
function isAndroidTablet(ua = navigator.userAgent) {
return /Android/.test(ua) && !/Mobile/.test(ua);
}
// Get Android version:
function getAndroidVersion(ua = navigator.userAgent) {
const match = ua.match(/Android (\d+\.?\d*)/);
return match ? parseFloat(match[1]) : null;
}
getAndroidVersion('Mozilla/5.0 (Linux; Android 14; Pixel 8)')
// 14
// Specific device model (Samsung, Pixel, etc.):
function getAndroidModel(ua = navigator.userAgent) {
const match = ua.match(/;\s([^)]+)\sBuild\//);
return match ? match[1].trim() : null;
}
getAndroidModel('Mozilla/5.0 (Linux; Android 14; Pixel 8 Build/UQ1A.240105.004)')
// 'Pixel 8'
WebView detection
In-app browsers (Facebook, Instagram, Twitter) and hybrid apps use WebView, which has modified UAs:
function isWebView(ua = navigator.userAgent) {
// iOS WebView:
const isIOSWebView = /iPhone|iPod|iPad/.test(ua) && !/Safari/.test(ua);
// Android WebView:
const isAndroidWebView = /wv/.test(ua) ||
(/Android/.test(ua) && /Version\/\d/.test(ua) && !/Chrome/.test(ua));
return isIOSWebView || isAndroidWebView;
}
// Facebook in-app browser:
function isFacebookBrowser(ua = navigator.userAgent) {
return /FBAN|FBAV/.test(ua);
}
// Instagram in-app browser:
function isInstagramBrowser(ua = navigator.userAgent) {
return /Instagram/.test(ua);
}
// Line app:
function isLineBrowser(ua = navigator.userAgent) {
return /Line\//.test(ua);
}
Real-world UA strings reference
iPhone Safari (iOS 17):
Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Mobile/15E148 Safari/604.1
iPad Safari (iPadOS 17, reports as macOS):
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2 Safari/605.1.15
iPad Safari (older iPadOS):
Mozilla/5.0 (iPad; CPU OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1
Android Chrome (Pixel 8):
Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36
Android Tablet Chrome:
Mozilla/5.0 (Linux; Android 13; SM-T870) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Facebook in-app browser (iOS):
Mozilla/5.0 (iPhone; CPU iPhone OS 17_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 [FBAN/FBIOS;FBDV/iPhone16,1;...]
Handling the iPadOS 13+ problem
// The safe combined check for "any Apple tablet":
function isAppleTablet() {
const ua = navigator.userAgent;
// Old iPadOS (iPad in UA):
if (/iPad/.test(ua)) return true;
// New iPadOS 13+ (reports as Mac, but has touch):
if (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1) return true;
return false;
}
// Server-side: you can't detect new iPadOS without maxTouchPoints
// Only client-side JS can reliably detect iPad post-iPadOS 13
// Server-side fallback: serve full desktop to all macOS UAs,
// let client-side JS adjust if needed
Related tools
- User Agent Parser — parse any UA string online
- User Agent String Examples — UA string reference
- Browser Detection JavaScript — feature vs UA detection
Related posts
- Bot Detection Using User Agent Strings — Googlebot, Bingbot, and Crawlers — Identify search engine crawlers, social media bots, and malicious scrapers from …
- Browser Detection in JavaScript — Feature Detection vs User Agent Parsing — Detect browsers, OS, and device type in JavaScript using user agent strings, fea…
- User-Agent Client Hints — Modern Browser Detection Without UA Sniffing — User-Agent Client Hints replace UA string parsing with structured HTTP headers. …
- Device Type Detection — Mobile, Tablet, Desktop in JavaScript — Detect whether a user is on mobile, tablet, or desktop using user agent strings,…
- User Agent String Examples — What UA Strings Look Like in 2025 — User agent strings identify browsers, operating systems, and devices. Here's wha…
Related tool
User Agent Parser
Parse any User-Agent string into browser, OS, device, and engine. Or detect your own. Built on the maintained ua-parser-js dataset.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.