<link href> or <style> for css?

It doesn't matter if you do all the error checking in the world, or if you have the most beautiful graphics, if your site or application design isn't usable, it's not going to do well. Get input and advice on usability and user interface issues here.

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

<link href> or <style> for css?

Post by Sindarin »

I am working in a website that will possibly require different stylesheets.

I've been using <link href> to link to different stylesheets, but lately this idea stroke me, why not turn the css file into a php document and include it inside the page using the <style> tag instead?
I thought that this would be faster as no additional requests would be made to the server for the css files and also it could have the benefit to use php tags to e.g. specify and generate a path for images like <?php echo $image_path ?>test.png

What do you think of this idea?
kirk93
Forum Newbie
Posts: 5
Joined: Sun Mar 21, 2010 8:32 am

Re: <link href> or <style> for css?

Post by kirk93 »

Hi
<link href="your-style.css" rel="stylesheet" type="text/css" media="screen" />
is the best way and fasted for my website. may be different you you use an java or mysql on the page?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: <link href> or <style> for css?

Post by Darhazer »

<link rel> requires HTTP request. On the other hand, it can be cached, and inline CSS (style) cannot. So in my opinion the best way is to have the common CSS in an external file, and the page-specific to be inline to save HTTP request, as well as loading and parsing of CSS that is not used on the specific page.
User avatar
carnavia
Forum Newbie
Posts: 18
Joined: Sun Jul 18, 2010 11:27 pm

Re: <link href> or <style> for css?

Post by carnavia »

Use <link> for css. Make it external and make it a PHP file with the header as:

Code: Select all

 <?php header("Content-type: text/css"); ?>
Post Reply