RCIX
RCIX

Reputation: 39467

Linking an external CSS stylesheet to HTML

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?

Upvotes: 3

Views: 832

Answers (3)

Yash
Yash

Reputation: 102

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">

Upvotes: 2

Daniel Vassallo
Daniel Vassallo

Reputation: 344551

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.

Upvotes: 6

Asaph
Asaph

Reputation: 162851

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" />

Upvotes: 7

Related Questions