Take the 2-minute tour ×

How would i detect that the device in use is an Android for a mobile website?

I need to apply certain css attributes to the Android platform.


share|improve this question

2 Answers 2

up vote 81 down vote accepted

Take a look at that : http://davidwalsh.name/detect-android


var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
  // Do something!
  // Redirect to Android-site?
  window.location = 'http://android.davidwalsh.name';


if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
  header('Location: http://android.davidwalsh.name');
share|improve this answer
you sir are a legend. –  Xavier May 17 '11 at 13:30
don't forget to also check for android tablets: googlewebmastercentral.blogspot.com/2011/03/… –  user235064 May 17 '11 at 13:35
It's worth noting that this does not always work for android devices as, for example, the user agents which are reported by Kindle Fire HD devices do not contain the word 'android' at all. –  djbp Jun 11 '13 at 13:54
Different versions of Android have different features, how about adding version detection? Useful when segmenting Gingerbread from Jelly Bean. The older doesnt support positon: fixed, just for example. So, things like backstretch won't work on Gingerbread. See: stackoverflow.com/questions/7184573/… –  Slopeside Creative Aug 9 '13 at 18:12
The navigator.userAgent approach doesnt work on samsung galaxy devices. There's no 'Android' in the browser spec. –  AsafK Feb 6 at 0:18

js version, catches iPad too:

var is_mobile = /mobile|android/i.test (navigator.userAgent);
share|improve this answer
Doesn't work because it catches many devices, not just Android as the question requires. –  NickG Dec 20 '13 at 9:57

Your Answer


