0

Could anyone tell me why my page isn't linking to the CSS? I have both HTML and CSS file in the same folder.

Here's my HTML:

<!DOCTYPE html>
<html>
  <head>
      <link rel="stylesheet" type = "text/css" href="style.css">
      <title> Flying Fish Painting Company </title>
  </head>
  <body>
     <h1> Flying Fish Painting Company </h1>
  </body> 
</html>

And this is my CSS:

h1{
    color:blue;
  }
6
  • Could you please check that they have the correct file types? Commented Oct 26, 2017 at 3:18
  • Hey, ton! 'What do you mean by correct file types? As in the CSS is saved as 'style.css' and the HTML is saved as 'index.html'? Commented Oct 26, 2017 at 3:28
  • Are you running a web server (Node, IIS, etc) or just loading the file from the filesystem? Commented Oct 26, 2017 at 3:37
  • no web server. It's just a preview version I believe. It's saved to my desktop, and the preview will open up in Firefox when I click it. Commented Oct 26, 2017 at 3:41
  • It works fine for me. Is the css named style.css, and in the same folder as the html file? Commented Oct 26, 2017 at 3:46

4 Answers 4

2

It works fine for me.

If I put both files in the same folder then it also works

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

if you put your CSS file in a different folder that time.

Syntax:

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

You should write:

<link rel="stylesheet" type="text/css" href="css/style.css">
Sign up to request clarification or add additional context in comments.

Comments

0

Could you check the spaces:

type = "text/css"

change to:

type="text/css"

1 Comment

Spacing does not matter
0

Is this your exact html code or just an example?

There are a couple of spaces before and after your = on the type you should remove.
Personally I find it better to put all css in a subfolder. It shouldn't make a difference however it makes for easier organization.
For a single css style like that I would just put it in line the html unless this is something you want across several html files.

1 Comment

Jarod, This is my exact HTML. It's my first site, so I'm just trying to make sure I can actually link to the CSS file in general, whether it's necessary in this situation or not. I do, also, have the CSS in a separate file, and both the HTML and CSS are in the same folder. Also I fixed the spaces, and it didn't work :/
0

There is nothing wrong with this code except the spaces mentioned above. Works fine for me. Check for typos and make sure it is in the same folder.

4 Comments

They are in the same folder, although one file (the HTML file) has a picture of the web broswer next to it, and the other (the CSS file) has a picture of a document. Does that mean anything? Also my Sublime program is unregistered. Does that have an effect?
All I did was copied and pasted your code saved both on my desktop and opened the html file worked fine for me. The software may or may not have something to do with it i dont know. You can use notepad or the equivalent with mac just save the file as html, and css
Wow, somehow that worked! When they were both saved to the desktop it worked, but when they were in the same folder it didn't hrm. Any idea why? Regardless, thanks so much for your help!
No Problem Glad to Help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.