0

I'm creating a website.
My .html file is not linking to my .css file.

HTML:

<!DOCTYPE html>
<link href="https://fonts.googleapis.com/css2?family=Montserrat" rel="stylesheet">
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="404.css">
  <title>Pacebi - 404</title>
</head>
<body>
body text here
</body>
</html>

CSS:

body{
  font-family:'Montserrat';
  background-color:whitesmoke;
  color:black;
}
button{
  font-family:'Montserrat';
  background-color:whitesmoke;
  color:black;
}

Note that I've done the exact same thing to my other pages. This is specifically not working.
Could it be the fact this is a 404 page in any way?

Using an online web programming tool (replit.com). (OS would not affect. If it did, I've been editing from a Windows 10 and Android 11.

Update: It's working now, I cleared browser cache and put the path for 404.html in the same directory as my .css.

1
  • Hi ! So far so good :) Is your css file on a real http server or on the local filesystem of the computer ? If live server, could you provide us a link ? Commented Oct 9, 2021 at 19:54

7 Answers 7

1

i think your linked it wrong, well that is the only reason why it would not be connected

Sign up to request clarification or add additional context in comments.

Comments

0

Your code is correct. It's working fine on my side.

enter image description here

Comments

0

Yes. I'd change the name to something still relevant and see if the issue persists.

Comments

0

I checked with your code. It was working fine on my side. Could be a cache issue. Empty your browser cache and refresh it. It should work fine then.

Comments

0

It is not linking because your css body code should be the html file code and if that doesn't work I think your file name should be style.css cuz 404 is a interactive code for windows to follow your file path.

1 Comment

i'm using an online linux-based IDE at replit.com (that would also not explain my android 11 problems) and style.css is reserved for my other pages. could you also clarify on the first part?
0

It does not matter if your file is named 404.css or 503.css, it has to be in the same folder as your html file in your case.

That said, it seems your CSS is ill-formed or badly copy/pasted. You miss the tag name for which you are defining the first styles. i guess it's the body

MISSING_SELECTOR {
  font-family:'Montserrat';
  background-color:whitesmoke;
  color:black;
}
button{
  font-family:'Montserrat';
  background-color:whitesmoke;
  color:black;
}

Also you can add the type but that does not matter much:

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

Browsers HTML parsers are quite robust to the fact they don't really need the HEAD and BODY tags in order to know where to place the objects. Nevertheless try to put all your links and metas inside the head if you are using it.

Good luck! :)

Comments

0

I tried the code on replit.com and it worked fine for me:Result on replit.com

The only reasons why I think it might not have worked on your computer is if you named the file incorrectly, or if you put the css in a different folder.

Suppose you did it like this, then it would not work because the file path would be incorrect:CSS file with incorrect path

The second reason is if you put the css in a different folder, so the file path would be wrong:CSS file in different folder

Comments

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.