Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML How to Make a Website Creating HTML Content Include External CSS

linking my css file with my html file. I just linked my css file to my html, but when I previewed my page, nothing cha

I refreshed my page, but the preview still looks the same prior to me adding the link element. Please let me know what I am doing wrong. Thank you!

Please post the code following the Markdown Cheatsheet for formatting. Post both the html and css.

Thanks, Theodore! I really appreciate you offering to help. It turns out that my trouble was as a result of a computer glitch, but it's working fine now. :)

2 Answers

Hi Linda

If you haven't figured it out, it all depends on where the file is in the folder structure. If you have the css file in a folder, then you have to make sure you include the folder to the link referencing the file. And the link to the css file MUST be in your header like this:

<html>
  <head>
    <title>Page Title</title>
    <link href="main.css"> <!-- THIS is where the file has to go... 
         between the opening <head> and closing </head> tags 
         shown here above and below -->
  </head>
  <body>
     <!-- web page content goes here -->
  </body>
</html>

As for how the link has to look, it needs to be as follows:

In your main directory (where your index file is), if you've got the css file in the same folder as the index (like this):

alt text

...then you'll need to make sure that the link to the css file looks like this:

<link href="main.css">

(where "main.css" is the name of your css file).

If, however, you have the css file is in a subfolder (like this):

alt text

...then you'll need to make sure that the link to the css file looks like this:

<link href="css/main.css">

Where "css" is the name of the folder that holds your "main.css" file -- or again, whatever the names of your folders and files are....

If you have it set up like that and it still doesn't work, then as Theodore says, you should post your code.

~Tracy

Hi Tracy,

Thanks for your help! I followed your instructions last night, and it still wouldn't work. I was frustrated and decided to take a break. This morning I started up again and refreshed the page just as I did the night before, and it worked. I think it was just a computer glitch.

~ Linda

Yeah probably :) Sometimes it just helps to reboot the computer. Glad it finally worked for you!

Something to note: When I've coded things in the past, and I've been completely frustrated with it not working how I think it should, or I can't seem to solve the problem, that's always a good sign to take a break. I remember one time, I was struggling with something in PHP, and I just couldn't figure it out. I was tired, and had been working on a lot of other things so I hadn't had a lot of sleep. I got up from the computer and went to take a short nap. I had been asleep about for about 20 minutes, when the solution just popped into my head. I sat up, realizing I had it, went back to my computer, and within a few minutes I had the script working. I had intended to take a 30-40 minute nap/break, but apparently 20 minutes was all I needed.