Blog for web designers

How to add class only for safari

How to add class only for safari

add class only in safari

In this post I will show you how to add class only for safari. Sometimes safari behaves the css style very unusually and break the design. In order to accomplish it and make it work like others browsers we need to add a unique class only for safari.

How to add class only for safari

We will use a piece of Javascript code that will add a class inside a body. Its a pure javascript code so you don’t need any library file. Just simple copy and paste it into your document inside the head tag.

if (navigator.userAgent.indexOf('Safari') != -1 && 
    navigator.userAgent.indexOf('Chrome') == -1) {
        document.body.className += " safari";

Thank you for reading the post. Hope it helps.

Santosh Shah

My name is Santosh Shah and blogs at

Reader Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.