By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,493 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,493 IT Pros & Developers. It's quick & easy.

link or @import

P: n/a
Which one is better:

<link rel="stylesheet" href="style.css" type="text/css" />

or

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

and why?
TIA

Steven
Jul 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"steven" <st***********@pandora.be> wrote in message
news:kA*******************@phobos.telenet-ops.be...
Which one is better:

<link rel="stylesheet" href="style.css" type="text/css" />

or

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

and why?


Some browsers don't support the @import method... most notibly NN4. I
recently switched from the link method to the @import method when I decided
I could stop supporting NN4 and let the page degrade gracefully on that
browser. Read this article for more on which browsers support which method
(note, there are variations using the @import method... URL with and without
quotes, etc. See this article:
http://w3development.de/css/hide_css_from_browsers/

Regards,
Peter Foti
Jul 20 '05 #2

P: n/a
steven wrote:
Which one is better:

<link rel="stylesheet" href="style.css" type="text/css" />

or

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

and why?
TIA


Neither's better. They're different. "link" is used for multiple
styles and for grouping different files into a single file. For
example, try this in Mozilla or Opera:
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="style1.css" type="text/css" title="Style 1" />
<link rel="alternate stylesheet" href="style2.css" type="text/css"
title="Style 2" />

style.css is persistent (like @import). But style1.css and style2.css
are selectable alternate styles. More info is in the HTML 4 spec.

Note that in certain browsers (such as IE), the distinction is blurred;
but per the spec (and in standards-oriented browsers), the two are very
different.

HTH

Jul 20 '05 #3

P: n/a
steven wrote:
<link rel="stylesheet" href="style.css" type="text/css" />
This is the XHTML way (lose the '/' and its the HTML way)
<style type="text/css">
@import url("style.css");
</style>


This uses more markup, creates a new style sheet, then imports another style
sheet into it. Its rather inefficient IMO.

--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #4

P: n/a
"David Dorward" <do*****@yahoo.com> wrote in message
news:bv*******************@news.demon.co.uk...
steven wrote:
<link rel="stylesheet" href="style.css" type="text/css" />
This is the XHTML way (lose the '/' and its the HTML way)
<style type="text/css">
@import url("style.css");
</style>


This uses more markup, creates a new style sheet, then imports another

style sheet into it. Its rather inefficient IMO.


Uses more markup?! Barely, if at all. Consider this:

<link rel="stylesheet" href="style.css" type="text/css" />

58 characters (not including the new line at the end).

Now consider this:

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

61 characters (not including the new line at the end). Note that I could
have removed the 3 spaces before @import to get 58 characters and it would
have been exactly the same as the link method. But indentation aside, they
are practically identical, and a few extra bytes is hardly a reason to not
use this method.

In addition, this method allows for stylesheets to be hidden from browsers
that implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.

Regards,
Peter Foti
Jul 20 '05 #5

P: n/a
Peter Foti wrote:
In addition, this method allows for stylesheets to be hidden from browsers
that implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.


Yes you can:
<link ... media="screen,projection">
--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #6

P: n/a
"David Dorward" <do*****@yahoo.com> wrote in message
news:bv*******************@news.demon.co.uk...
Peter Foti wrote:
In addition, this method allows for stylesheets to be hidden from browsers that implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.


Yes you can:
<link ... media="screen,projection">


Interesting. I thought that because NN4 supports media="screen" that the
above would still work with it. But apparently that's not the case. In
addition, this should ONLY exclude NN4, whereas the @import methods will
always exclude additional browsers (though in some cases, it may be better
to exclude more... namely IE3 and sometimes IE4).

Ok, you've converted me back to link again! :)

-Peter
Jul 20 '05 #7

P: n/a
Peter Foti wrote:

this method allows for stylesheets to be hidden from browsers that
implement them in a horrendously broken way (NN4 for example). You
can't do that using the link method.


Of course you can. Use the @import statement in the stylesheet that is
<link>ed. That introduces 2 stylesheets, I suppose, but it's how I've
always done it.

--
Brian (follow directions in my address to email me)
http://www.tsmchughs.com/

Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.