IE7 and @import media types

Warning This article was written over six months ago, and may contain outdated information.

The more I use IE7, the more I hate it. Yes, it’s more stan­dards-com­pli­ant and fea­ture-rich than IE6; but if the best you can say about your brows­er is that it’s bet­ter than IE6, you’re not start­ing from a strong posi­tion. IE7 is bet­ter than IE6 as receiv­ing ten smacks in the head is bet­ter than receiv­ing twelve.

The rea­son I’m annoyed at IE7 today is that I’ve just found out they still haven’t imple­ment­ed media types on the @import rule. If you’re not sure what this is, it’s a short­hand way to apply stylesheets only to spe­cif­ic media. Say, for exam­ple, we want to apply an exter­nal stylesheet called print.css which will apply only to print­ed doc­u­ments; easy enough, you just do this:

<style type="text/css">
@import url('print.css') print;

Easy, right? Not for IE7, no. It just does­n’t read the stylesheet at all. OK, there are a num­ber of alter­na­tives to this;

<style type="text/css" media="print">
@import url('print.css');

for exam­ple; or just using the plain old link element:

<link rel="stylesheet" href="print.css" media="print">

But that’s not the point. Using media types on the @import rule was imple­ment­ed in CSS2, which became a release can­di­date in 1998. That’s at least eight years that the IE team have had to think about imple­ment­ing this. If they already sup­port media types in the link and style ele­ments, how hard could it have been to add it to the @import rule?

7 comments on
“IE7 and @import media types”

  1. Thanks for the write­up on this, it had been con­fus­ing me for a while why my @import state­ments weren’t work­ing in IE7… I nev­er even thought this would be a fea­ture they have yet to imple­ment. It’s real­ly a shame.

  2. indeed, they should have imple­ment­ed this long time ago. :(

  3. […] chance to run a few more tests to find out what’s new (and what’s not) in IE8. Good: @import media types seem to be imple­ment­ed; Bad: XHTML still isn’t parsed, so every­one who thinks they are coding […]

  4. I’m I wrong, or does IE7 not sup­port the @import rule at all??

    Dave Campbell [August 24th, 2008, 04:28]

  5. @ Dave: No, it does sup­port @import; just not with media types.

  6. Its annoy­ing (to put it mild­ly) and I wast­ed sev­er­al days trac­ing why script that had pre­vi­ous­ly worked but did­n’t with a slight­ly changed design. Yes the prob­lem was ie7 and @import with media select 

    I then realised that media select was­n’t need­ed as the call­ing script was already media select­ed via its html link. Had it not been then I could have media select­ed with­in the import file.

    I’ve hat­ed ie since I 1st tried css back in my ns4 days — maybe ie8 will change my mind — and watch out for fly­ing pigs.

    James Montague [March 5th, 2009, 12:28]

  7. Thanks a ton! I found this post and I believe it explains why my Google AJAX Imple­men­ta­tion of a video bar isn’t work­ing in IE7 and works in every­thing else! Imple­ment­ing your workaround right now…