Home » Web development » Cross Browser Compatibility » How to write Browser Specific HTML CSS in PHP

Here is code which Web designer and web developer can use to make some code browser specific only in php. Many times Web designer and web developer require to put in browser-specific HTML / CSS in your files, because most often the pages are rendered differently (esp. IE). You can detect what browser the user is using with the help of PHP.

Demo: Browser Specific HTML CSS in PHP

In your PHP file, put the following code first:

$msie = strpos($_SERVER["HTTP_USER_AGENT"], 'MSIE') ? true : false;  
$firefox = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox') ? true : false;  
$safari = strpos($_SERVER["HTTP_USER_AGENT"], 'Safari') ? true : false;  
$chrome = strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome') ? true : false; ?>

And use where you want to execute code based on browser

if ($firefox) {
echo 'you are using Firefox!';
echo '<br ?-->';

// Safari or Chrome. Both use the same engine - webkit
if ($safari || $chrome) {
echo 'you are using a webkit powered browser';
echo '

// IE
if ($msie) {
echo '
you are using Internet Explorer
echo '

// Not IE and for all other browsers
if (!$msie) {
echo '
you are not using Internet Explorer
echo '


If you are looking for IE-only conditional statements, refer http://www.quirksmode.org/css/condcom.html

Other useful resources:


Wordpress Freelancer, Joomla Freelancer Web designer Mumbai india, Wordpress web developer India, Joomla Web developer india, Outsourcing web project india mumbai

By Santosh Kori Published: October 10, 2012 Professional Freelance Website developer 5 stars based on 65 reviews Total time: 24 hour 00 min Wordpress Joomla XHTML CSS jQuery HTML5 eCommerce CSS3 ☞ Offers low cost freelance web designing, asp php asp.net web development services from Mumbai India. Freelance web designer & developer Mumbai India.