views:

74

answers:

3

I know about CSS like this

.style{ .. }

I want to know how to add external css file in a HMTL page. One more thing using such external css dose it relay speed up the page load time.

+11  A: 

In your HEAD, add:

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

the css file itself does not contain <style> tags.

Pekka
you forgot `media="screen"` and `title="mycss"`
Jonno_FTW
you don't need those.
Sneakyness
@Jonno_FTW Those are not required. Default behaviour is good enough for almost all common situations.
ceejayoz
@Jonno_FTW: why would a title attribute be useful? Is it even allowed? Never seen it before in a `<link>`.
Geert
Titles are useful when your page has an alternate stylesheet (say a high-contrast or larger-font one): in Firefox you can switch between stylesheets with View->Page Style.
djn
That's good to know. +1
Pekka
+5  A: 

The simplest way to do so is to add a stylesheet link to your document HEAD section:

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

Doing so will reduce the performance on the first load (since the system must request two files instead of one) but improve subsequent performance because the style sheet remains in cache for a while.

Victor Nicollet
+1 and deleted own duplicate.
Dead account
+1  A: 

From StackOverflow's page:

<link rel="stylesheet" href="http://sstatic.net/so/all.css?v=5885"  type="text/css">

I don't think it will improve speed much unless the same CSS file is shared across multiple webpages in your website (so the browser can cache it). Otherwise there's the penalty of creating an extra HTTP connection to retrieve the CSS.

ruibm
Don't forget you can look at the source of any website to see how they do it.
Sneakyness
I guess the most common is to add a link so that you can organize your code better and also have a UI template that works across the whole website. Overall, it's better to stick with a standalone CSS. (not sure what you meant Sneakyness).
ruibm