Is there an standard way to detect IE and Edge browsers in css? I saw responses for detecting in javascript file but I am looking for one in css
Asked
Active
Viewed 4.7k times
36
-
1Possible duplicate of https://stackoverflow.com/questions/32201586/how-to-identify-microsoft-edge-browser-via-css – flamusdiu Apr 20 '17 at 20:13
5 Answers
80
For IE 9 and lower, load a conditional stylesheet:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->
IE 10 and up doesn't support this, so you have to use media queries:
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS */
}
For Edge 12-15:
@supports (-ms-accelerator:true) {
/* Edge 12+ CSS */
}
EDIT
For Edge 16+
@supports (-ms-ime-align:auto) {
/* Edge 16+ CSS */
}

Claire
- 3,146
- 6
- 22
- 37
-
Let's say I want to detect if it is IE or Edge then the backgournd shouldn't be fixed, what should I do? – AlreadyLost Apr 20 '17 at 20:17
-
-
1
-
thank you, Can I ask one more question? what is the difference between -ms-accelerator and -ms-ime-align:auto? I just saw someone mentioned that as well for Edge. Thank you – AlreadyLost Apr 20 '17 at 20:47
-
Both are simply CSS hacks. Basically you're checking to see if the browser supports a specific feature by "sniffing" for it. In this case, ms-accelerator is a hardware accelerator supported by edge, and ms-align-auto aligns the Input Method Editor. What they do is irrelevant to your situation. The point is that you can use them to sniff out browsers and apply conditional CSS. I digress though, this is likely temporary. As new browser versions and features are released, you will need to update these 'hacks'. Javascript feature detection is the best way forward. Google it. – Claire Apr 20 '17 at 21:02
-
11
The accepted answer for Edge isn't working in Edge 16.
This alternative works:
@supports (-ms-ime-align:auto) {
/* IE Edge 16+ CSS */
}
Via https://stackoverflow.com/a/32202953
(Adding new answer as I don't have comment privileges.)

Jarrod Drysdale
- 111
- 1
- 5
9
Not sure about edge, but to target ie 10/11 you can use:
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
//styles
}

Carl Edwards
- 13,826
- 11
- 57
- 119

JusMalcolm
- 1,431
- 12
- 10
5
For supporting edge 12+ and 16+ as one liner
@supports (-ms-accelerator:true) or (-ms-ime-align:auto) {
// your css here
}

MR_AMDEV
- 1,712
- 2
- 21
- 38
4
All in one:
@media all and (-ms-high-contrast: none), (-ms-high-contrast: active),
@supports (-ms-accelerator:true) or (-ms-ime-align:auto) {
/* All CSS is here */
.example {
/* ... */
}
}

Blarzek
- 160
- 12
-
For style class `.example`, apply the desired style in Internet Explorer 10/11 and Edge 12+. – Blarzek Mar 25 '20 at 10:35