How to attach a CSS stylesheet to an HTML document

  • by Zach (166)
  • Time to complete: 1 minute

Linking a CSS file to an HTML file allows you update the styling of the HTML document by editing the CSS file. This is especially useful if, for example, you have hundreds of pages that you'd like to style from one central location. Using CSS, you can com

1

If you have multiple HTML files, you will need to complete these steps for each one.

2

In your HTML document, paste the following between the opening and closing brackets.

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

^ The href="X" denotes the location of your file. There's a special consideration to make when denoting this location:

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

^ The denotation above suggests that inside of the directory containing your HTML file is a directory called "css" which contains a file called "style.css".

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

^ The denotation above (using a slash) suggests that the file style.css is located inside a directory in your root called "css".

<link rel="stylesheet" type="text/css" href="https://howchoo.com/css/style.css" />

^ The denotation above is a valid use of an absolute URL.

3

Save your HTML file and you're done!