Detect mobile device browsers, not only screen width

Anton Belev picture Anton Belev · Aug 13, 2013 · Viewed 7.7k times · Source

I know that I can activate some styling with media query like that:

/* Magic for mobile devices */
@media (max-width: 33em ) 
{
}

however I don't really like this approach since it checks only against screen width. I found this java script code for detecting mobile browsers and now I need the same check with CSS

if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) {
        // some code..
}

Is there a CSS equivalent of this js?

Answer

koningdavid picture koningdavid · Aug 13, 2013

You could use the following:

<link rel="stylesheet" type="text/css" href="mobile.css" media="handheld">

This will target small or handheld devices.