tags:

views:

68

answers:

3

I'm new to HTML/CSS and I want to have one of my HTML files use a CSS file. How can I do it?

+7  A: 

In the <head> tag of your HTML document add a line that looks like this:

<link rel="stylesheet" type="text/css" href="/path/to/your/style.css" />
Asaph
+6  A: 

I suggest you start by going through the w3schools CSS Tutorial.

This will guide you to define your CSS styles, which is what comes immediately after adding the style sheet to your HTML.

Daniel Vassallo
I plan to head there to write my CSS file thanks though :)
RCIX
Any halfway *decent* CSS tutorial (and there are many) will also discuss how to invoke it in your HTML. Don't put the cart before the horse. Write the CSS and then invoke it.
pavium
Thankfully, this CSS is only for personal use so i (probably) won't be subjecting anyone to seeing my horrible CSS ;).
RCIX
+2  A: 

You can specify external style sheets with the following attributes of the LINK element:

  • Set the value of href to the location of the style sheet file. The value of href is a URL.

  • Set the value of the type attribute to indicate the language of the linked (style sheet) resource. This allows the user agent to avoid downloading a style sheet for an unsupported style sheet language.

  • Specify that the style sheet is persistent, preferred, or alternate:
  • To make a style sheet persistent, set the rel attribute to "stylesheet" and don't set the title attribute.
  • To make a style sheet preferred, set the rel attribute to "stylesheet" and name the style sheet with the title attribute.
  • To specify an alternate style sheet, set the rel attribute to "alternate stylesheet" and name the style sheet with the title attribute.

In this example, we first specify a persistent style sheet located in the file mystyle.css:

<LINK href="path_to_css_file" rel="stylesheet" type="text/css">
Yash
changed accepted to this for the comprehensive explanation
RCIX
Don't capitalize html tags. The various html specs prefer or require lowercase tag names.
Asaph