Ive been hearing about using @import for linking stylesheets to webpages lately… Can someone explain this to me, and why/when it should be used over the normal <link href=…> way? Is it meant to replace <link href> or work alongside it? I’ve seen it used both ways in code lately and it’s got me a bit confused as to its place within “best practices”…
No, it was used to hide styles from Netscape 4 (IE4 was the main browser that @import worked in at that time).
The only time you’d have an issue using multiple <link> tags to supply all the styles is if you are also supplying alternate styles also using link tags. To properly control what gets swapped out and what gets swapped in when using alternate stylesheets you’d need to make sure you only use one active stylesheet per media with the rest being marked as alternates. That’s where you’d need to use @import if you wanted to share styles between the alternatives.
Any issues related to import vs <link> are long gone (besides an IE8 bug where imported stylesheets inside of imported stylesheets are limited to a certain number, but that’s unlikely you will run into that)
So really it’s all up to you (it’s easier to specify media type in the <link> way though (also easier to remmeber)
It’s up to you, but ultimately most people go with <link>
Since I hadn’t considered the merits of changing to @import untill I saw this thread, I’ve got a question about @import–if you use one sheet with a <link> or @import in your HTML, and nest all the others in that sheet with @import, would that count as one request, or would the browser still request each nested sheet anyway?
I don’t understand why people use separate stylesheets in most cases. You can organize stuff into one stylesheet so it’ll remain readable and easy to follow without adding unnecessary requests to the server. With exception for conditional comments (which require the link anyway as you can’t use them within CSS documents) I just use media queries within the master stylesheet, less additional requests to the server and that could give it a minor speed edge.
From what I understand, @import has some issues, including slightly slower display speeds, and the FOUC, or “flash of unstyled content.” with older IE browsers (I think this goes back to IE5). Most designers use them to conceal subsidiary stylesheets from older IE browsers, which don’t recognize the @import command. (Someone correct me on this last one if I’m wrong.) Basically, there’s no compelling reason of which I’m aware to use it unless you need to head-fake an old version of IE .