Is there a Google Chrome-only CSS hack? Many previously existing hacks that used to work for Chrome now are being picked up (used) by other browsers. I need one that targets Google Chrome, but not also other browsers like Mozilla Firefox, Safari, or Microsoft Edge.
-
http://css-infos.net/properties/webkit – Ram May 30 '12 at 07:50
-
Mozilla reads *what* properly too? And why is the question tagged jQuery if its about CSS? – James Allardice May 30 '12 at 07:50
-
1in mozilla top:56px show other place and in crome other place...but in ie7 ok – Sandy May 30 '12 at 08:06
-
Any joy with my answer @Sandeep? – Alex May 31 '12 at 09:32
-
http://browserhacks.com/ – vsync Mar 11 '14 at 12:17
-
This works in Edge also strange but true. – Denzil Sep 23 '16 at 19:06
6 Answers
Sure is:
@media screen and (-webkit-min-device-pixel-ratio:0)
{
#element { properties:value; }
}
And a little fiddle to see it in action - http://jsfiddle.net/Hey7J/
Must add tho... this is generally bad practice, you shouldn't really be at the point where you start to need individual browser hacks to make you CSS work. Try using reset style sheets at the start of your project, to help avoid this.
Also, these hacks may not be future proof.
Only Chrome CSS hack:
@media all and (-webkit-min-device-pixel-ratio:0) and (min-resolution: .001dpcm) {
#selector {
background: red;
}
}

- 1,959
- 18
- 19
-
Thx its working only on chrome not on Ipad or iphone like others solution – user956584 Jul 18 '14 at 09:06
-
The reason is not the hack (the hack posted here is one I created and posted at browserhacks) -- the problem is that the iPad version of Chrome is using the Safari engine. It responds to Safari hacks only, not Chrome ones. Other versions of Chrome are in fact Chrome and work accordingly. – Jeff Clayton Aug 06 '14 at 12:40
-
-
-
1Is the last condition `... and (min-resolution: .001dpcm)` required? i checked and found that it will work without that (at least in latest chromes) – S.Serpooshan Dec 27 '16 at 10:22
-
1Yes it is absolutely required, the two parts rule out different browsers. Without it the hack does not work right because other browsers will be allowed as well. So yes, you need to use the complete hack not just a part of it. – Jeff Clayton Jul 24 '17 at 12:32
Try to use the new '@supports' feature, here is one good hack that you might like:
* UPDATE!!! * Microsoft Edge and Safari 9 both added support for the @supports feature in Fall 2015, Firefox also -- so here is my updated version for you:
/* Chrome 29+ (Only) */
@supports (-webkit-appearance:none) and (not (overflow:-webkit-marquee))
and (not (-ms-ime-align:auto)) and (not (-moz-appearance:none)) {
.selector { color:red; }
}
More info on this here (the reverse... Safari but not Chrome): [ is there a css hack for safari only NOT chrome? ]
The previous CSS Hack [before Edge and Safari 9 or newer Firefox versions]:
/* Chrome 28+ (now also Microsoft Edge, Firefox, and Safari 9+) */
@supports (-webkit-appearance:none) { .selector { color:red; } }
This worked for (only) chrome, version 28 and newer.
(The above chrome 28+ hack was not one of my creations. I found this on the web and since it was so good I sent it to BrowserHacks.com recently, there are others coming.)
August 17th, 2014 update: As I mentioned, I have been working on reaching more versions of chrome (and many other browsers), and here is one I crafted that handles chrome 35 and newer.
/* Chrome 35+ */
_::content, _:future, .selector:not(*:root) { color:red; }
In the comments below it was mentioned by @BoltClock about future, past, not... etc... We can in fact use them to go a little farther back in Chrome history.
So then this is one that also works but not 'Chrome-only' which is why I did not put it here. You still have to separate it by a Safari-only hack to complete the process. I have created css hacks to do this however, not to worry. Here are a few of them, starting with the simplest:
/* Chrome 26+, Safari 6.1+ */
_:past, .selector:not(*:root) { color:red; }
Or instead, this one which goes back to Chrome 22 and newer, but Safari as well...
/* Chrome 22+, Safari 6.1+ */
@media screen and (-webkit-min-device-pixel-ratio:0)
and (min-resolution:.001dpcm),
screen and(-webkit-min-device-pixel-ratio:0)
{
.selector { color:red; }
}
The block of Chrome versions 22-28 (more complicated but works nicely) are also possible to target via a combination I worked out:
/* Chrome 22-28 (Only!) */
@media screen and(-webkit-min-device-pixel-ratio:0)
{
.selector {-chrome-:only(;
color:red;
);}
}
Now follow up with this next couple I also created that targets Safari 6.1+ (only) in order to still separate Chrome and Safari. Updated to include Safari 8
/* Safari 6.1-7.0 */
@media screen and (-webkit-min-device-pixel-ratio:0) and (min-color-index:0)
{
.selector {(; color:blue; );}
}
/* Safari 7.1+ */
_::-webkit-full-page-media, _:future, :root .selector { color:blue; }
So if you put one of the Chrome+Safari hacks above, and then the Safari 6.1-7 and 8 hacks in your styles sequentially, you will have Chrome items in red, and Safari items in blue.

- 1
- 1

- 7,053
- 1
- 31
- 36
-
More on my blog: http://jeffclayton.wordpress.com/2014/07/22/the-chrome-and-safari-css-hacks-collection/ and the test page here: http://browserstrangeness.bitbucket.org/css_hacks.html#webkit – Jeff Clayton Aug 06 '14 at 12:44
-
I have added many new hacks for many browser versions on my test page and blog. – Jeff Clayton Aug 17 '14 at 15:42
-
On first blush, this makes it seem like Chrome supports compound selectors in `:not()` as per Selectors 4. However, it looks more like Chrome is simply ignoring the `*` in the argument. `:not(*:root)` and `:not(*[fakeattr])` work fine, but `:not(html:root)` and `:not(html[fakeattr])` do not. It's not clear from Selectors 3 if `*` should be counted as a simple selector for the purposes of `:not()` when not used alone (and in Selectors 4 it's probably irrelevant anyway). Either way, a very interesting find. – BoltClock Aug 18 '14 at 05:49
-
Looks like Chrome is aware of `:past`, `:current` and `:future` as well, but I have no idea how exactly it implements them (I can't get any elements to match any of them, or `:not(:current)`, but I can get every element to match `:not(:past)` and `:not(:future)`). At the very least, though, it recognizes them, which allows it to use this hack. – BoltClock Aug 18 '14 at 06:00
-
You are correct. Check my edits above for my responses. :not(:past) works the same as future, past and current, you are correct. And thanks for the kind words. Check my blog and examples for more. I only posted one of each, not all due to duplication of purpose. Keep up the good research! – Jeff Clayton Aug 18 '14 at 13:33
-
While some CSS hacks are in fact programmed by the company, like -webkit- and -moz- prefixes which we make use of, often they are based on how CSS error checking is handled in the browser. In Internet Explorer 7 for example, when it found an error in CSS it would often continue anyway, ignoring the error and still executing the CSS. Others read the CSS until they find an error then decide not to execute it. Often then you find combinations that seem to not make any sense but still work for reasons like that, and others of course. – Jeff Clayton Aug 18 '14 at 15:20
-
Yep. Looks like they're back in full force. I'll admit, I wasn't expecting to see them again. I thought we were over them, but I guess some things just won't ever go away. – BoltClock Aug 18 '14 at 15:24
-
Not sure they will ever go away, reading MDN (moz dev network) the -moz- extension is in their build cycle. They create CSS code - usually based on standards but not always, give it a -moz- extension, and test for a while, then wait until most or all browsers accept the method then they make a non-moz version. After time, they sometimes remove the moz one as well. – Jeff Clayton Aug 18 '14 at 15:34
-
Oh I meant hacks that exploit parsing bugs that sometimes result in invalid CSS (aka unsafe hacks). – BoltClock Aug 18 '14 at 15:41
-
I see - I thought you meant hacks in general. I agree with you... if all browsers acted like they were supposed to... Granted I have spent much of this last year testing these things to find ones that people did not ever try before. Much of it was for browserhacks.com so at least for these and many of the new hacks you see on that site, you can actually blame me ;) – Jeff Clayton Aug 18 '14 at 16:08
To work only chrome or safari, try it:
@media screen and (-webkit-min-device-pixel-ratio:0) {
/* Safari and Chrome */
.myClass {
color:red;
}
/* Safari only override */
::i-block-chrome,.myClass {
color:blue;
}}

- 289
- 3
- 9
You could use javascript. The other answers to date seem to also target Safari.
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
alert("You'll only see this in Chrome");
$('#someID').css('background-position', '10px 20px');
}

- 2,154
- 2
- 21
- 24
I have found this works ONLY in Chrome (where it's red) and not Safari and all other browsers (where it's green)...
.style {
color: green;
(-bracket-:hack;
color: red;
);
}
From http://mynthon.net/howto/webdev/css-hacks-for-google-chrome.htm

- 41
- 6