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

CSS

HTML/CSS linking

i need help with linking my html document with my CSS. i am using Sublime text 2.

2 Answers

Lachlan Mitchell
Lachlan Mitchell
9,278 Points

This can easily be achieved through the use of the html link element, but it can be hard to get your head around at first. To start with, open up your html document in Sublime Text. In the header section, add:

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

You want to change "PATHTOCSSHERE" with the path to the css file you are trying to link the html page to.

If that css file is in the same directory (or folder) as the html page, it's as easy as typing in "style.css" with the name of the css file matching whatever you called yours. I just used style.css to simplify things :) However, if the css file is in another directory (say inside a folder called css) you would need to type out the path to it relative to the html document. In this case, you'd type "css/style.css". Generally, it's a good idea to store your css files in a css folder within the root directory (the highest folder of your page structure), as that keeps it easy to remember where you put them all later :p

Here's an example of a full header from one of my pages.

<head>
    <title>My Page</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
</head>

Hope I was able to help! If you still have questions, feel free to comment back :)

vote!

Hey Lachlan, When you were telling me to link my HTML document using the link you gave me as an exmaple it wasnt working for me. Would it make a difference if i am using a PC laptop instead of a macbook?

Rashii Henry
Rashii Henry
16,433 Points

im not too familiar with CSS but I'm pretty sure it has nothing to do with you operating system.

It could probably be a typo somewhere.

For example, if your filenames aren't spelled correctly and things of that sort.

i am still having some problems with linking my CSS to my HTML... i have no clue what i am doing wrong. i used the exact link you gave me.

Thank you very much that really helped me a lot.