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

linking css to html in visual studio

Hello, I am trying to link css to html in my first project in visual studio, and it won't link. I have watched every you tube tutorial and made more pages different ways to try to link them. Is there something wrong with my code? The file path is copied directly.

<!DOCTYPE HTML> <html lang="en">

<head> <title>Clay McDermott, Web Developer </title> <link href="C:\Users\clayton.mcdermott\Desktop\CSS.css" rel="stylesheet" type="text/css">

<h1> CAPTAIN CLAY MCDERMOTT, WEB DEVELOPER </h1>

Hello Clay, as I see from your file path you're using the Desktop directory as a project folder which isn't a good practice. Inside the Desktop directory, try to create a folder, and call it, for example, web-developer, and then create an "index.html" file and a "style.css" file, and now you use this tag to link them together: <link rel="stylesheet" type="text/css" href="style.css"

Good luck!

2 Answers

Hi Clay,

El Mehdi is absolutely correct with the advice offered. That shouldn’t be the reason that the file doesn’t open correctly on your local machine (although if you used that same file path on a deployed site it would not work). I’m thinking the issue is probably that the browser is not able to find your file, and my guess would be to take a look at the clayton.mcdermott directory in the Users directory as it’s a bit strange to see a dot in a directory name. Make sure that file path is spelled correctly (as good practice for debugging filepath issues if you’d like).

But piggybacking off of El Mehdi, it’s good practice to create a project folder for each coding project and to store all of your files there.

Thank you both for the excellent feedback I will work in getting the files into a project folder and hopefully that works.