Home > front-end development > Browser CSS hacks

Browser CSS hacks

April 15th, 2009

I don't use CSS hacks anymore. Instead I use IE's conditional comments to apply classes to the body tag.

Nonetheless, I wanted to document every browser-specific css selector and style attribute hack I've seen. Plus there's no way to provide stylesheets to only Safari, I believe.

With these you'll be able to better target IE, Firefox, Chrome, Safari and Opera from within the css.

So here are go:

Comprehensive List of Browser-Specific CSS Hacks

 
/***** Selector Hacks ******/
 
/* IE6 and below */
* html #uno  { color: red }
 
/* IE7 */
*:first-child+html #dos { color: red } 
 
/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }
 
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }
 
/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }
 
/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }
 
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }
 
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }
 
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}
 
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}
 
 
/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }
 
/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }
 
/* Everything but IE6-8 */
:root *> #quince { color: red  }
 
/* IE7 */
*+html #dieciocho {  color: red }
 
/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }
 
/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }
 
/* FF 3.5+ */
body:not(:-moz-handler-blocked) #cuarenta { color: red; }
 
 
/***** Attribute Hacks ******/
 
/* IE6 */
#once { _color: blue }
 
/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }
 
/* Everything but IE6 */
#diecisiete { color/**/: blue }
 
/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }
 
/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }
 
/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */
 
/* IE8, IE9 */
#anotherone  {color: blue\0/;} /* must go at the END of all rules */

If you'd like to take a gander by yourself:

Test page with all these hacks present.

View the test page at browsershots.org

(Thx to Webdevout, Evotech, and Jeffrey, porneL, and commenters.)

I should point out I'm not including weird hacks like the voice-family ones or anything particularly ugly.

Somewhat related…

Here are the most concise browser sniffs I've seen. (Not that browser sniffing is good or anything…)

Update 2009.06.03 – I added the suggestions left on Ajaxian and in the comments and updated the browser versions to consider Safari 4, IE 8, and Chrome 2.

Update 2009.08.03 – I added some new Firefox hacks from @pornelski, which are very unique in that the target selector is not a child like the rest of them. More explanation on his site.

Update 2009.11.10 – Added #prop: value IE<=7 hack. I prefer it much less to *prop.

Update 2010.01.24 - Added prop: value!ie hack. Thx @miketaylr for the tip.

Update 2010.04.07 – Clarification on :nth-of-type(n) from Estelle Weyl

Update 2011.04.11 – the new \0/ hack from here and here. It's invalid and must go at the end of all other rules.. so it's a pretty dangerous hack, but at the same time.. its a happy arms-raised guy, so I guess it balances out. :)

Update 2011.05.18 – updated the \0/ and \9 one to note that it works in IE9 as well. thx Mathias Bynens.

Update 2011.05.19 – added :not(:-moz-handler-blocked) one from lea verou.

Freeform addendum

2011.05.23: Okay some freeform notes from recent research. hopefully i'll clean these up later….

Mathias wrote about safe CSS hacks Read that. Also I should clarify which of the hacks on this page are recommended and which are …. tricky and nasty.. (which is many of them)…

Mathias is also on the hunt for an IE8-only CSS hack. Hope we unearth one!

Siggi, in the comments wrote about the // comment hack to match IE6, 7:

    min-height:300px;
    //height:300px; /* matches only IE6, IE7 */

Then the CSS magician Thierry Koblentz offered up these selector hacks…

selector, x:-IE7 { } /* IE7 only */
selector,{} /* lte ie7 */
.suckyie6.someClass {} /* lte ie6  */

The last one is done via the ie6 .double.class bug — the .suckyie6 class could be anything you're not using.

And the skillful necolas posted more details on IE css hacks:

/* Property prefix hacks */
 
/* IE6 only - any combination of these characters */
_ - £ ¬ ¦
 
/* IE6/7 only - any combination of these characters */
! $ & * ( ) = % + @ , . / ` [ ] # ~ ? : < > |
 
 
/* @media hacks */
 
/* IE6/7 only (via Keith Clarke) */
@media screen\9 { }
 
/* IE6/7/8 (via Keith Clarke) */
@media \0screen\,screen\9 {} 
 
/* IE8 (via Keith Clarke) */
@media \0screen { }
 
/* IE8/9 */
@media screen\0 { }

Paul Irish front-end development

  1. April 24th, 2009 at 13:05 #1

    ie8 do not do ?

  2. April 24th, 2009 at 15:28 #2

    "/* IE 7 and below */"

    Pretty sure *:first-child+html doesn't target below IE7, otherwise nice list.

  3. Klaus Hartl
    April 24th, 2009 at 16:00 #3

    html:first-child #cinco applies to Safari 2 as well (tested 2.04 at that time)

    In addition to that list here are the ones I was using in my latest project:

    html[xmlns*=""]:root <selector> = Applies: Safari 3.1, Safari 2.04
    *|html[xmlns*=""] <selector> = Applies: Safari 3.1, Safari 2.04, Opera 9.25
    :root *> <selector> = Hides from IE
    * > <selector> = Hides from IE6
    property /**/: value; = Hides from IE6

  4. April 24th, 2009 at 16:16 #4

    missing this one:
    /* IE7/8 */
    *+html #nueve { color: red }

  5. technova
    April 25th, 2009 at 03:58 #5

    Seen elsewhere :

    ALL IE VERSIONS:

    #somediv{
    width: 100px\9;
    }

    IE8 STANDARDS MODE ONLY:

    #somediv{
    width /*\**/: 100px\9;
    }

    —-
    credits : http://my.opera.com/dbloom/blog/2009/03/11/css-hack-for-ie8-standards-mode

  6. April 27th, 2009 at 16:39 #6

    I've managed to narrow all my css hacks down to only the property hacks. It is nice to see the other options here, but I hope I never have to use them.

  7. May 5th, 2009 at 15:42 #7

    Great list to have just in case! Thanks for sharing

  8. June 3rd, 2009 at 08:36 #8

    Check that in Safari.I write in my css code u specify above like
    html[xmlns*=""] body:last-child #login-box_one p.last { position:relative; top:-8px;}
    but it does not affect on my xhtmlfile. my safari(on windows) vesrion is "Safari 4 Public Beta(528.16)

  9. June 3rd, 2009 at 18:31 #9

    @travis, I'm not seeing *+html foo work in any browser. Hmm…

    @technova, In my tests width /*\**/: 100px\9; also target IE7 in addition to IE8 standards. I left a comment on the Opera blog.

    @akbar You're right, it no longer works in Safari 4 beta. Thx. :)

    Thanks everyone for their submissions and changes.

  10. June 4th, 2009 at 01:09 #10

    Then how can fix the css bugs in safari. any solution. In other browser issues i solved like Ie7 bugs. i use the ( /* IE7 */*:first-child+html #dos { color: red } ) shown in above. in other words how can i fix the safari problem . please this is very urgent requirement

  11. June 4th, 2009 at 08:11 #11

    @akbar, you can probably use the safari/chrome hack above. (I assume it affects chrome as well)

    /* saf3+, chrome1+ */
    @media screen and (-webkit-min-device-pixel-ratio:0) {
     div.myClass  { color: red  }
    }

    This will catch Safari3, Safari4, Chrome1, Chrome2. (Not Safari 2)

  12. janogarcia
    June 4th, 2009 at 11:56 #12

    Hi, What has happened to the Attribute Hacks?

  13. June 4th, 2009 at 13:28 #13

    @janogarcia , Hah. Thanks. In my update I stripped the hacks out of this post. They were present in the demo page though. Fixed now!

  14. janogarcia
    June 4th, 2009 at 17:27 #14

    Thanks for the quick fix!

  15. Phil Ricketts
    July 14th, 2009 at 04:40 #15

    I use this to select for IE7 only:

    #id element.class{
    color: blue;
    .color: red}

  16. Yogesh Singh
    July 15th, 2009 at 02:08 #16

    thanks friend i have solved my problem of safari

  17. Ashwin SM
    July 17th, 2009 at 09:06 #17

    Great Hacks for the different browsers. But one thing, is there any hack that only works for Opera9+..

  18. August 3rd, 2009 at 11:10 #18

    @Phil Ricketts, using a period in the attribute hack targets both IE6 and IE7. So it's equivalent to the *attribute which is more common.

    @Ashwin SM, I haven't yet seen one for Opera 9. There claims to be one here, but on my demo page, I don't see it catching in Opera.

  19. August 3rd, 2009 at 11:18 #19

    @Ashwin SM, For Opera 9 you could try this:

    Add a class of 'hypen-ated' to your body tag.

    #foo { color: red; } /* applies to all browsers */
    body[class|="hypen-ated"] #foo { color: black; } /* applies to everything but opera 8,9 */

    This technique is courtesy of javascriptkit.

  20. September 7th, 2009 at 08:10 #20

    Here's an alternative approach, that uses server-side User-Agent sniffing and then puts classes on the BODY tag, such as "Browser-Engine-WebKit" or "Browser-DesktopOpera-10-0-1":
    http://ernstdehaan.blogspot.com/2009/06/combining-css-and-user-agent-sniffing.html

  21. September 7th, 2009 at 10:09 #21

    @Ernst de Haan Ernst, while it's true your technique will help target individual browsers, it negates the ability to do page-level caching. So for high traffic sites, I don't consider it as useful.

  22. Carlos
    October 14th, 2009 at 16:00 #22

    thanks for posting this !!

  23. François
    October 22nd, 2009 at 11:47 #23

    Hi Paul, I found this page via David Bloom's blog. Thanks so much for this doubleplusgood page!

  24. October 28th, 2009 at 16:26 #24

    Thanks Paul, those Safari hacks come in handy!

  25. November 12th, 2009 at 06:07 #25

    Defintively a great article Paul. Thanks a lot.
    Just a question regarding Opera 10.01 since I didn't see any hack for it in your demo page. Is there any one for this browser?

  26. December 29th, 2009 at 17:54 #26

    FYI – - the webkit selector hack needs 'body' before basic tags such as h4 tags in order for them to be targeted accurately. hope that helps!

  27. January 22nd, 2010 at 02:28 #27

    Hi,

    I happened to see your post and find it very informative. I would like to share a link where a software engineer has share a tip on "CSS hack for Safari Browser".

    Here is the link:
    http://www.mindfiresolutions.com/CSS-hack-for-Safari-Browser-672.php

    Hope you find it useful and of assistance.

    Thanks,
    Bizz

  28. January 24th, 2010 at 15:01 #28

    @Bizz, The one described is captured here. thanks!

  29. January 28th, 2010 at 03:36 #29

    Thanks for the great summary of available CSS hacks. One correction:

    Your code sample matches also IE7 because you used a ";"

    #veinte { color/*\**/: blue\9; }

    If you want to address only IE 8 you have to omit the ";".

    #veinte { color/*\**/: blue\9 }

    What I also found out. With this hack it is not possible to add more than one rule inside the brackets. If you need more CSS rules, than you have to write each in a separate definition.

    #veinte { color/*\**/: blue\9 }
    #veinte { background-color/*\**/: yellow\9 }

  30. January 30th, 2010 at 05:51 #30

    Paul,

    Thanks for this comprehensive list. I didn’t know about !ie, that one’s pretty cool.

    I don't use CSS hacks anymore. Instead I use IE's conditional comments to apply classes to the body tag.

    Hear hear. I used to have one extra CSS file for every different version of IE. However, to reduce the amount of additional HTTP requests for IE, you could just use one ie.css file, containing the CSS for IE6, IE7 and IE8, and use the CSS hacks you mentioned in there. Performance-wise, this seems to be the best solution.

  31. February 3rd, 2010 at 03:33 #31

    Thank You For This Hacking code.But I want userfrndly hacking code of google chrome.If You Have then plz publish.

  32. February 3rd, 2010 at 19:42 #32

    After several days I found your page and since I am a illiterate developer
    or amateur webpage builder I ask:
    Where shoul I put the
    /***** Selector Hacks ******/
    list that you offer here.

    Thank you hoping to hear from you
    jorge

  33. February 3rd, 2010 at 20:30 #33

    Thkxs again. I will do use it and
    let you know if I got it right.
    jorge

  34. James
    February 18th, 2010 at 18:59 #34

    Just wanted to say thanks for the efforts. This article saved me a lot of stress.

    Keep up the good work.

  35. February 24th, 2010 at 09:26 #35

    I am now using these hacks (all in one CSS file) instead of three different files (using conditional commands) for the different IE versions:

    /*IE ≤ 8:*/ foo { property: value\9; }
    /*IE ≤ 7:*/ foo { *property: value; }
    /*IE6:*/ foo { _property: value; }

    Thanks for this awesome collection, Paul!

  36. zolid
    March 12th, 2010 at 09:43 #36

    Hi, just found out by accident:

    #.veinticinco, x:-moz-any-link, x:default { color: red }

    This will only match in Firefox 3 on Windows, not Mac! Dunno if it'll work with ID's, this would work for the class .veinticinco

  37. March 22nd, 2010 at 06:34 #37

    wow thanks, that was really helpful! :)

  38. March 22nd, 2010 at 11:06 #38

    Here's a IE8-selector hack:

    div.class { color: red; }
    div.class, #ie8#fix { color: blue; }

    This code will set color to blue in browsers, except for IE8. In IE8 it will be red.

  39. March 29th, 2010 at 14:01 #39

    Thanks a lot for this list! Very helpful to have in my toolbox!

  40. chok
    March 31st, 2010 at 04:21 #40

    Hi
    Thanx, but the Safari and Chrome hack* are not valid…

    *This hack :

    @media screen and (-webkit-min-device-pixel-ratio:0) {
    	.photo_jenny {
    	margin-top: -5px;
    	}
    }
  41. March 31st, 2010 at 15:25 #41

    @chok
    very few of these hacks are actually *valid*
    for me, validation is a tool and not a goal. but that's just me..

  42. deos
    April 9th, 2010 at 04:51 #42

    just saw at the test page, the !ie-hack does not work at all in IE6 and 7 (tested with the tools IETester(IE6+7) and MultipleIEs(IE6)). are these tools broken or is it the hack?

  43. April 9th, 2010 at 11:10 #43

    @deos
    You spotted an error in my #id naming. I fixed it and things work as expected. :)
    Thanks!

  44. Digo
    April 15th, 2010 at 06:05 #44

    Really amazing for chrome browser

    @media screen and (-webkit-min-device-pixel-ratio:0) {
      .divname {
    	border: 0px solid red;
    	position: relative;
    	top: 5px;
      }
    }
  45. April 15th, 2010 at 10:28 #45

    @Digo Yup! I got that one listed up there for both Chrome and Safari3+. :)

  46. April 22nd, 2010 at 01:31 #46

    Hi,really useful article.
    do you know what is the css hack for Android browser?
    android browser shows the checkbox a little lower !!!
    Thanks

  47. April 23rd, 2010 at 10:01 #47

    I do not, sadly. Probably a media query of some sort could identify it.

  48. Leonardo
    April 27th, 2010 at 12:52 #48

    Thanks man. Good Job!

    You saved my life =]

  49. May 4th, 2010 at 09:35 #49

    Good Job, Thank You!

  50. May 5th, 2010 at 18:09 #50

    Thanks.

    Also liked your mouse drawing.

    Came for css hack and started playing with mouse :)

  51. May 13th, 2010 at 12:31 #51

    I came across your post while having some browser compatibility issues and I must say I absolutely love your background. Perfect break from the frustration of browsers lol… ;] will def be back to play when i get too frustrated…

  52. Nagaraju
    May 21st, 2010 at 02:02 #52

    This is perfect hack for IE8 only

    .color  {
        color: #0FC/;
    }
  53. Nagaraju
    June 7th, 2010 at 04:53 #53

    This is perfect hack for IE8 only

    .color
    {
    color: #0FC/;
    }

  54. Nagaraju
    June 7th, 2010 at 04:58 #54

    IE8 hack css

    .color
    {
    background:blue/;
    }

    you have to write (backslash zero slash)

  55. June 23rd, 2010 at 11:20 #55

    I came across your site when I finally had enough of hacking CSS and decided to learn how to do it right. Very interesting tips you have noted, but where can I find out the justification for them, i.e. to help me understand better, is there a big CSS resource that actually covers ‘best practices’ in minute detail? I just need to understand why I should things the way I should.
    Thanks.

  56. July 6th, 2010 at 21:55 #56

    @css??
    I would recommend reading what I wrote here: http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/

    Nonetheless, ways to target things that arent IE are necessary.. So you may need to isolate some styles.. Thats why this list exists.

    however.. the big guidance is…. you can probably avoid these. use a css reset… know floats and box models well.. and you'll be using a lot less browser specific code than you used to.

  57. July 7th, 2010 at 08:48 #57

    @Thomas, this is interesting. Is this because IE8 is stricter than other browsers and won't allow two IDs on the same element? Your filter is more elegant and valid than the one, but I'd like to really understand it before using.
    Thanks :-)

  58. July 15th, 2010 at 16:44 #58

    Cheers!!! Your list was a godsend!!! Found exactly what I was looking for… Something that would exclude IE6&7.

    Thanks for posting this!

    Chris

  59. August 8th, 2010 at 16:15 #59

    I'm shocked! IE7 matches x:-moz-any-link, x:default selectors!

  60. Craig
    August 22nd, 2010 at 01:10 #60

    What's wrong with old fashioned Conditional Comments? They take care of most hacks and keep the ugly IE fixes in a separate file where they belong. Has anyone actually ever needed to apply hacks to a browser other than IE?

  61. Kim
    August 30th, 2010 at 03:20 #61

    thanks.. i was looking for ie8 hack..

  62. August 31st, 2010 at 11:23 #62

    Bad news, depending on how you look at it, from hacksville – IE9 beta and PP fall prey to the /9 hack. Which begs the next hack – how to target IE8 and not IE9. For the curious, I put up a little tool awhile back for testing hacks on your browser – it's selector-shell.appspot.com

  63. September 8th, 2010 at 04:19 #63

    @Lindsey Simon
    That does sound bad… :(

  64. GreLI
    September 13th, 2010 at 04:04 #64

    Hack with "\9" never worked in IE6 for me (standards mode, clean VM with full updated WinXP SP3). It is actual to have hack for FF3.5/3.6 (for border-images, shadows, gradients etc.) something like nth-child(n). Use "n" instead of "1" in "nth" selectors if you want to pass them not only first acceptable child.

  65. September 17th, 2010 at 02:12 #65
    body:last-child { ... } /* everything but ie<=8 */

    via devon govett

  66. deepdel
    September 24th, 2010 at 05:41 #66

    Does any one have IE8 specific CSS hack?

    None of the hack mentioned above for IE8 does not work. If it work then it also make changes in IE7 also.

    This is urgent, if some one can response.

  67. Mukesh
    October 5th, 2010 at 02:31 #67

    Could u pls provide css hack for Safari 3.2 and greater version.

  68. Zubair
    October 5th, 2010 at 04:32 #68

    @Kim
    Hi Kim,

    Please use this meta tag just below the title tag make sure that no js will apply above this meta tag.

    Given meta tag is apply all css which are written for IE7 to IE8.

  69. Zubair
    October 5th, 2010 at 04:35 #69

    Hi Kim,

    Please use this meta tag just below the title tag make sure that no js will apply above this meta tag.

     
  70. October 7th, 2010 at 11:10 #70

    Target Firefox 3 & 4 beta:

    @-moz-document url-prefix() { #featured-promos .cont li {margin-bottom:0} }
  71. max
    October 14th, 2010 at 09:01 #71

    That's brilliant! Thanks for gathering this in one page

  72. October 14th, 2010 at 11:22 #72

    I'm having a very strange problem. I have a table with navigation tabs. In between each link, I have a small table cell with a separator image. The separator image and currently selected nav tab were showing up 2 pixels too low. I used this hack to successfully fix the separator images:

    .navDiv {background-position/*\**/: 0px -2px !ie}

    The strange part is that it will not work for the selected nav tab, only the separator images/columns. Has anyone else run into this and/or have a secondary hack? Thanks in advance! ^.^

  73. Anna
    October 24th, 2010 at 21:51 #73

    Thank you very much…now I can go to sleep! This is the only hack for ie 8 i tried which functions. Great work!

  74. November 6th, 2010 at 01:30 #74

    Excellent set of tools ! However, the most efficient technique to get more comments still remains combining the two principles of writing killer content and interacting with other bloggers in your niche (especially by commenting in their blogs).

  75. November 16th, 2010 at 20:39 #75

    Thanks for this roundup Paul, this is the most complete list of selector hacks I've ever seen. Really helped me out just now.

  76. November 17th, 2010 at 03:44 #76

    @Nagaraju, your code samples are incorrect. The hack you’re talking about is property: value\;, which is similar to property: value;. Other than IE8, this also targets Opera 10.60 and IE9.

  77. November 17th, 2010 at 10:57 #77

    Jeez…I didn't know there were so many!

  78. sard
    November 18th, 2010 at 16:54 #78

    @Paul Irish
    hi ,
    I am trying to use the following code for chrome in netbeans 6.9.

    /* saf3+, chrome1+ */
    @media screen and (-webkit-min-device-pixel-ratio:0) {
    p { margin-top:20px }
    }

    However, it is not validating "and" and "(-webkit-min-device-pixel-ratio:0)" . If used without validation , there is no change in chrome but messes up otherwise decent IE and firfox page.
    Any suggestion….

  79. November 19th, 2010 at 04:07 #79

    You could use pseudo-elements/classes to target specific browsers as well. If part of a selector-group is invalid, the entire rule will be dropped. When using this to your advantage, the following CSS will display red text in Firefox and blue text in Chrome/Safari:

    p, .not-existing:-moz-any-link { color: red; }
    p, .not-existing:-webkit-any-link { color: blue; }

    Since it's a hack (just like other suggestions on this post) you should not rely on it. Given that WebKit implements over fifty pseudo-elements/classes alone and that they're not shy in Firefox either, it wouldn't be totally surprising if this behavior changes.

  80. sard
    November 19th, 2010 at 12:27 #80

    @Peter Beverloo

    Thanks Peter,
    your code for mozilla is working fine as intended, in my application.
    However, the text in IE changes to blue instead of chrome when second line is used. The text in chrome remains unchanged…. not sure what the issue is …

  81. December 8th, 2010 at 01:14 #81

    :root:focus works for only IE9 until you lose focus, :(. Come on ninjas, I have faith.

  82. December 14th, 2010 at 14:35 #82

    I found a good way to avoid 95% or more of my old needs for css hacks, by making a modification to the html I generate for my pages:

    Example html generated by php, or whatever:

     
     
     
    ... whatever head elements I need ...
     
     
    <!--[if IE ]><![endif]-->
    <!--[if lte IE 6]><![endif]-->
    <!--[if IE 7]><![endif]-->
    <!--[if gt IE 7 ]><![endif]-->
     
    ... regular page generation by whatever means ...
     
    <!--[if IE]><![endif]-->

    Then in my css, if I need to target ie's I can use:

    /*
    ** regular rule:
    */
    div#content h3.title { color:green;
                         }
    /*
    ** target all ie:
    */
    #IE_root div#content h3.title { color:green;
                                  }
    /*
    ** target ie6 and below:
    */
    #IE6_root div#content h3.title { color:green;
                                   }
    /*
    ** target all ie7:
    */
    #IE7_root div#content h3.title { color:green;
                                   }
    /*
    ** target all ie8:
    */
    #IE8_root div#content h3.title { color:green;
                                   }

    Obviously, this is still a hack, but not technically a css hack, but it does validate, and has greatly removed much of my stress from handling multiple ie css problems.

  83. December 14th, 2010 at 14:39 #83

    @jefkin
    hmm my first code block failed using html4strict, this is what it should look like:

    <!DOCTYPE ... >
    <head ... >
    
    ... whatever head elements I need ...
    
    </head>
    <body>
    
    
    
    
    
    ... regular page generation by whatever means ...
    
    
    </body>
    </html>
    
  84. December 14th, 2010 at 14:58 #84

    @jefkin
    Yup. I linked that technique at the top of this post. :)

  85. bahar
    January 3rd, 2011 at 03:20 #85

    I need a hack for ( firefox 2 only ), How?

  86. January 30th, 2011 at 21:44 #87

    Hi,

    I want background image flicking issues.

  87. January 31st, 2011 at 05:28 #88

    Hi,

    Thanks guys……..

    I am using safari version: 3.1.1, can any body tell me which code i will use for text color.

    Regards,
    Bharat

  88. January 31st, 2011 at 05:30 #89

    /* Safari 2 – 3.1 */
    html[xmlns*=""]:root #trece { color: red }

    Whats is this i am not understand……………..

    Can anybody explain me…………….

  89. January 31st, 2011 at 05:30 #90

    /* Safari 2 – 3.1 */
    html[xmlns*=""]:root #trece { color: red }

  90. January 31st, 2011 at 21:46 #91

    great, are you a spanish speaker?

  91. Hannah
    February 3rd, 2011 at 07:38 #92

    Thanks very much! Just solved a veryannoying problem with Chrome for me :)
    Regards, Hannah

  92. puppet Master
    February 14th, 2011 at 07:31 #93

    is there a way to target only ie8 quirks mode?

  93. March 2nd, 2011 at 12:00 #94

    This will target IE7

    * + html #dos {
    color: red;
    }

  94. hitman
    March 21st, 2011 at 20:02 #95

    For ie, the conditional tags are



    But what about for firefox? I would like to have a conditional tag targeting firefox, because I need to write a .css file targeting firefox browsers only.

  95. SalmanAbbas007
    March 24th, 2011 at 11:21 #96

    Awesome, Thanks alot :D
    Bookmarked ;)

  96. March 25th, 2011 at 02:56 #97

    and then Microsoft created…ie9! that recognize ie8 only hack but with a different behaviour.
    IN my case the problem is the vertical align in a input text. Ie8 is the only one that need a padding-top so with a
    .text-box{
    padding-top: 13px/ !important; /* IE 8 */
    }
    i thought would be ok but ie9 understand it so it push the text outside from my field…

  97. Tweety
    March 25th, 2011 at 03:03 #98

    hey! any one could help me to fix the alignment issue on Mac Firefox and Safari?

  98. March 27th, 2011 at 07:25 #99

    How is best IE, Firefox, Chrome, Safari and Opera ??

  99. randf
    April 15th, 2011 at 04:05 #100

    Hi there,

    Here is the hack for IE9

    #nav li.last-page-item a {
    padding-right:5px;
    }
    /* IE9 Hack */
    :root #nav li.last-page-item a{
    padding-right:8px\9;
    }

  100. April 16th, 2011 at 02:48 #101

    @randf Sadly, that’s using the \9 hack which has become unreliable in IE9. Also, I think this would target Opera as well.

  101. babu
    May 10th, 2011 at 18:51 #102

    any one help me this hack css is not supported mac os how can i fix this alignment issues

  102. May 13th, 2011 at 09:12 #103

    / matches IE9, too. :-(

  103. siggi
    May 20th, 2011 at 13:02 #104

    What about the "wrong comment" hack for IE 6 + 7?
    espacially for min-width and min-height?

        min-height:300px;
        //height:300px; /* IE6, IE7 */

    works also to override previous settings of other attributes, very handy for the double margin bug …

        margin:0 0.5em;
        //margin:0 0.5em 0 0.25em; /* IE6, IE7 */

    (assuming there is a element with float:left; before)

    with a little bit more effort (

    //html, body, { width:100%; height:100%; } /* IE6 IE7 */
    //#bodyContainer { overflow-y:scroll; } /* IE6 IE7 */

    ) it is possible to overcome position:fixed-problems with this technique ;-)
    why does it work?
    the double slash is not a valid CSS-comment, therefore the declaration will be ignored by all major browsers – except IE6 and IE7 !
    i use it quite often in my CSS, not sure,where i got i from.

  104. June 2nd, 2011 at 14:28 #105

    I'm pretty convinced that all these parser bugs are actually just Easter Eggs given to us by the browser makers to have some fun with every other new version they throw at us :-)
    It all started out so simple with our old buddy NS4 ignoring a LINK element that has an id attribute set, and now we're juggling with special characters.
    The Web's no much fun!

    René

  105. June 6th, 2011 at 19:04 #106

    The following "Firefox" hacks are not safe:

    #veinticuatro, x:-moz-any-link { color: red }
    #veinticinco, x:-moz-any-link, x:default { color: red }

    Because as my IE7 hack shows (selector, x:-IE7 {…}), IE7 should apply both the above rules.

  106. July 3rd, 2011 at 22:43 #107

    very nice article, thanks for sharing and good luck

  107. Darren
    July 5th, 2011 at 08:03 #108

    Old Internet Explorers – not working – NOTE: Modern/Advanced CSS selectors can 'trip' old IEs (8/7/6 etc). E.g:

    h1, li:nth-child(2), p {font-family: myNewFont; } will also fail the H1 and P elements in IE8.

    You might try the following instead:
    H1, p {font-family: myNewFont; }
    /*:root *> everything but IE6-8. (Not tested in IE5/4!)*/
    :root *> li:nth-child(2) {font-family: myNewFont; }

  108. July 19th, 2011 at 14:58 #109

    error spotted:

    /* IE7, IE8 */
    #veinte { color/*\**/: blue\9; }

    effects IE9 as well

  109. August 7th, 2011 at 01:55 #110

    @Paul Irish

    I found the solution here and its working perfectly.
    Thanks for sharing us.

  110. August 22nd, 2011 at 23:22 #111

    hey! any one could help me to fix the alignment issue on Firefox 5 version? any css hacks is there in firefox5?

  111. Sriharsha
    August 25th, 2011 at 05:07 #112

    Thanks a ton buddy !! Really helped me

  112. September 9th, 2011 at 12:54 #113

    This page rocks! Thanks for the save!

  113. Shailesh
    September 12th, 2011 at 13:03 #114

    Hi,

    I need a hack that only work for Safari 3+ browser.
    @media screen and (-webkit-min-device-pixel-ratio:0) is working for Chrome and Safari.
    My website is working fine in IE, FF, Chrome.
    is there any hack only for Safari 3+ Browser???

  114. September 20th, 2011 at 11:40 #115

    hi Paul

    I have made this web sites

    Look the curvy corner box

    It's look proper on i7,i8,Google chrome; Safari; Opera

    but the problem is the style which i used for i9{/} disturb my i8 style sheet {/9 or /*\**/}

    can u please tell me why this happen what will be the solution.

  115. October 7th, 2011 at 02:02 #116

    Actually you can target stylesheets directly to webkit browsers like Safari and Chrome.

    I found a solution to that problem here: http://webgyani.com/2010/03/how-to-serve-different-stylesheets-only-to-safari-and-chrome/

    In essence, all you need to do is to change the type attribute in the link to the stylesheet. The links to the Safari and Chrome specific stylesheets would then be something like this:

    I can confirm that this method works, but I don´t know if this is the most efficient way to target those two browsers or not.

  116. October 11th, 2011 at 11:34 #117
  117. December 1st, 2011 at 01:30 #118

    Great list to have just in case! Thank you very very musch :)

  118. December 4th, 2011 at 10:19 #119

    Here's my set: @media "not all" should not apply.

    /* Targets OP 7-11 (but not Op9!) incl. WebKits */
    @media not all and ( ... ) {...}
     
    /*OP 9+ and WebKit/Chrome 10+ however ignore*/
    @media not all and (0) {...}
    @media not all and (1) {...}
    /*but do accept */
    @media not all and (true) {...}
    @media not all and (false) {...}
    @media not all and (foobar) { /* invalid property */ }
    @media not all and (orientation) { /* valid prop but no comparison */ }
     
    /*FF3.5-7 accept signed values */
    /* this bug was fixed in FF8 */
    @media screen and (min-resolution: +72dpi) { /* FF fixes */ }
     
     
    /*IE8 only: throw a `:target` in the mix of selectors you DON'T want IE8 to read*/
    h1 {color:red} /* IE8 */
    .foo:target, h1 {color:#bad455} /* others */
  119. December 14th, 2011 at 15:36 #120

    Great and very useful list of hacks, thanks Paul

  120. December 21st, 2011 at 05:21 #121
    body:not(:-moz-handler-blocked) #someid .class .class

    The above statement doesn't seem to work of FF7, it works only if I get rid of #someid and only leave classes.

  121. Ananthan Iyer
    December 27th, 2011 at 23:55 #122

    Very thanks buddy, good work….

  122. Christian Augustin
    January 1st, 2012 at 12:24 #123

    The "Everything but IE6" attribute hacks has to have a space before the /**/ to work (not shown in the comprehensive list but present in the original). Without the space IE6 is happy with it …

  123. Christian Augustin
    January 1st, 2012 at 12:47 #124

    BTW, the "Everything but IE6" attribute hack works only for IE in standards compliant mode, the attribute is used in quirks mode …

    The hack to hide from IE8 shown some comments above is really handy (it works for me with IE8 using Trident 8 rendering) – this one was really missing! My thanks to René.

  124. Christian Augustin
    January 1st, 2012 at 13:00 #125

    The IE 7/8 attribute hack from the list ("color/*\**/: blue\9;") does not work for me, but "color /**/: blue\9;" does — but for IE 7/8/9.

  125. January 3rd, 2012 at 10:07 #126

    I want hack only for safari and I use this code

    @media screen and (-webkit-min-device-pixel-ratio:0){
    .opensource {width:1000px;}
    }

    but it affect on both chrome and safari ….
    I used safar 5

  126. January 23rd, 2012 at 06:51 #127

    nice list of hacks, thx

  127. January 26th, 2012 at 19:07 #128

    In the attribute hacks section, you've got #diecinueve { color: blue\9; } as IE6-8. It also targets IE9.

  128. January 31st, 2012 at 12:01 #129

    @sard
    I found that the x:-moz-any-link hack does not work with IE that are not real IE such as running in wine or multiple IEs in windows. The css parser is broken in those instances so that it does apply the webkit or -moz specific rules where real installation works correctly.

  1. April 25th, 2009 at 08:36 | #1
  2. April 27th, 2009 at 09:01 | #2
  3. April 28th, 2009 at 02:48 | #3
  4. April 29th, 2009 at 22:03 | #4
  5. May 21st, 2009 at 01:20 | #5
  6. June 23rd, 2009 at 14:25 | #6
  7. August 18th, 2009 at 02:46 | #7
  8. October 24th, 2009 at 06:23 | #8
  9. December 27th, 2009 at 13:04 | #9
  10. January 7th, 2010 at 16:57 | #10
  11. January 13th, 2010 at 18:25 | #11
  12. January 20th, 2010 at 10:56 | #12
  13. January 25th, 2010 at 18:21 | #13
  14. March 14th, 2010 at 12:58 | #14
  15. March 14th, 2010 at 15:38 | #15
  16. April 12th, 2010 at 19:45 | #16
  17. April 19th, 2010 at 23:05 | #17
  18. April 21st, 2010 at 21:03 | #18
  19. May 11th, 2010 at 12:15 | #19
  20. May 18th, 2010 at 11:46 | #20
  21. July 21st, 2010 at 10:15 | #21
  22. July 30th, 2010 at 23:16 | #22
  23. September 2nd, 2010 at 13:57 | #23
  24. October 17th, 2010 at 14:05 | #24
  25. October 26th, 2010 at 21:05 | #25
  26. October 28th, 2010 at 00:02 | #26
  27. November 19th, 2010 at 09:04 | #27
  28. November 21st, 2010 at 16:32 | #28
  29. December 22nd, 2010 at 21:48 | #29
  30. February 11th, 2011 at 17:20 | #30
  31. February 11th, 2011 at 18:26 | #31
  32. February 12th, 2011 at 01:11 | #32
  33. February 20th, 2011 at 23:07 | #33
  34. March 17th, 2011 at 04:59 | #34
  35. April 2nd, 2011 at 00:25 | #35
  36. April 15th, 2011 at 17:13 | #36
  37. April 18th, 2011 at 04:28 | #37
  38. April 19th, 2011 at 00:08 | #38
  39. April 19th, 2011 at 20:34 | #39
  40. April 25th, 2011 at 01:26 | #40
  41. April 27th, 2011 at 06:16 | #41
  42. April 28th, 2011 at 08:25 | #42
  43. April 29th, 2011 at 05:01 | #43
  44. May 2nd, 2011 at 06:16 | #44
  45. May 27th, 2011 at 10:21 | #45
  46. May 27th, 2011 at 10:28 | #46
  47. May 29th, 2011 at 06:47 | #47
  48. June 2nd, 2011 at 07:13 | #48
  49. June 16th, 2011 at 01:12 | #49
  50. June 16th, 2011 at 06:39 | #50
  51. June 16th, 2011 at 07:02 | #51
  52. June 16th, 2011 at 09:33 | #52
  53. June 16th, 2011 at 10:04 | #53
  54. June 16th, 2011 at 11:29 | #54
  55. June 16th, 2011 at 13:29 | #55
  56. June 16th, 2011 at 16:40 | #56
  57. June 16th, 2011 at 19:12 | #57
  58. June 16th, 2011 at 19:30 | #58
  59. June 17th, 2011 at 03:20 | #59
  60. June 17th, 2011 at 04:31 | #60
  61. June 22nd, 2011 at 06:18 | #61
  62. June 23rd, 2011 at 06:21 | #62
  63. June 27th, 2011 at 05:16 | #63
  64. June 30th, 2011 at 03:11 | #64
  65. July 18th, 2011 at 04:43 | #65
  66. August 1st, 2011 at 23:17 | #66
  67. August 2nd, 2011 at 02:15 | #67
  68. August 10th, 2011 at 04:54 | #68
  69. August 12th, 2011 at 09:41 | #69
  70. September 2nd, 2011 at 10:15 | #70
  71. September 25th, 2011 at 08:14 | #71
  72. October 10th, 2011 at 05:06 | #72
  73. October 12th, 2011 at 05:38 | #73
  74. November 4th, 2011 at 02:56 | #74
  75. November 8th, 2011 at 05:08 | #75
  76. November 26th, 2011 at 06:40 | #76
  77. November 29th, 2011 at 09:02 | #77
  78. January 10th, 2012 at 06:57 | #78
  79. January 30th, 2012 at 09:01 | #79
  80. February 1st, 2012 at 22:44 | #80

For code blocks, use <pre lang="javascript">. css and html4strict are also accepted.

i left this space here for you to play. <3