I inserted your code, verbatim, into a JSFiddle, and the background is red, as you wanted.

The code is not the issue, then. Instead, its a problem of the stylesheet loading properly. Try some or all of the following:

  • Check your stylesheet name, and that it is the same in the directory as it is in your HTML code; make sure stylesheet.css exists properly.
  • Double-check that the file exists in the right place, which is in the same directory as your index that you are opening.
  • Make sure the stylesheet is loading. In Chrome, if you right-click -> inspect element and go to the sources tab, you can see all loaded resources, including your CSS. If it's not loading here, it could be that it tries to load from your cache. You can force Chrome to load sites without the cache by opening the inspector again, clicking on the gear menu, and checking "Disable cache (while DevTools is open)', and reloading your site.
  • Check your local apache/webhost server to make sure that it doesn't have any settings blocking the loading of certain files or types of files. This is assuming you are running one and not just opening the file in Chrome/IE. If that is the case, you should have no problems with the file loading.
  • Make sure you saved the file. It's silly, but I can personally vouch for the time when I couldn't make my site update, and I forgot to save/update the file I was viewing.
Answer from Ava on Stack Overflow
Top answer
1 of 7
1

I inserted your code, verbatim, into a JSFiddle, and the background is red, as you wanted.

The code is not the issue, then. Instead, its a problem of the stylesheet loading properly. Try some or all of the following:

  • Check your stylesheet name, and that it is the same in the directory as it is in your HTML code; make sure stylesheet.css exists properly.
  • Double-check that the file exists in the right place, which is in the same directory as your index that you are opening.
  • Make sure the stylesheet is loading. In Chrome, if you right-click -> inspect element and go to the sources tab, you can see all loaded resources, including your CSS. If it's not loading here, it could be that it tries to load from your cache. You can force Chrome to load sites without the cache by opening the inspector again, clicking on the gear menu, and checking "Disable cache (while DevTools is open)', and reloading your site.
  • Check your local apache/webhost server to make sure that it doesn't have any settings blocking the loading of certain files or types of files. This is assuming you are running one and not just opening the file in Chrome/IE. If that is the case, you should have no problems with the file loading.
  • Make sure you saved the file. It's silly, but I can personally vouch for the time when I couldn't make my site update, and I forgot to save/update the file I was viewing.
2 of 7
1

Hello, perhaps it helps to someone:

css files have to be transmitted stating "text/css" as content type (while your html page content is usually "text/html").

It is important to state the right value for transmission, because browsers check it.
I had this problem with Delphi, trying to state "DOCTYPE HTML" in a WebBroker application to use HTML5, and the problem has been solved setting it in the variable reponse.contenttype. If you use a web server, I suppose you have to put the file in the right folder for example, or set this attibute in the right place to instruct your server to send the right contenttype.

Have a nice day!
🌐
DhiWise
dhiwise.com › post › why-is-my-css-not-linking-to-my-html-troubleshooting-guide
Why is My CSS Not Linking to My HTML:Solved
October 10, 2024 - Forgetting to close the <link> tag or mistyping the file path are just the tip of the iceberg. Ensure you’re not placing the <link> tag in the wrong section of your HTML document and that you’re using the correct file extension.
People also ask

Why is my CSS file not affecting my HTML?
Ensure your CSS file is correctly linked in the HTML `` section, the file path is correct, and there are no errors in your CSS code.
🌐
dhiwise.com
dhiwise.com › post › why-is-my-css-not-linking-to-my-html-troubleshooting-guide
Why is My CSS Not Linking to My HTML:Solved
How do I link a CSS file to an HTML file in a different folder?
Use a relative file path from your HTML file to your CSS file, like: ```html ```
🌐
dhiwise.com
dhiwise.com › post › why-is-my-css-not-linking-to-my-html-troubleshooting-guide
Why is My CSS Not Linking to My HTML:Solved
Can I use multiple CSS files for one HTML page?
Yes, you can link multiple CSS files to a single HTML document to organize your styles for different sections of your website.
🌐
dhiwise.com
dhiwise.com › post › why-is-my-css-not-linking-to-my-html-troubleshooting-guide
Why is My CSS Not Linking to My HTML:Solved
🌐
Reddit
reddit.com › r/html › why isn't my css file linking to my html page?
r/HTML on Reddit: Why isn't my CSS file linking to my HTML page?
April 20, 2022 -

I have two files in the same folder.

index.html and style.css

When the CSS is inside the HTML code itself, it works just fine.

<!DOCTYPE HTML>

<html>

<head>

    <link rel="stylesheet" href="style.css">
    <title>Title</title>

</head>

<body>

    <div class="header">
        <h1> Heading </h1>
    </div>

</body>

</html>

What's wrong then? I've removed <style> and every other HTML code from the CSS as it should be, yet nothing works.

I tried replacing href with src - still nothing happens.

Appreciate any help!

🌐
Codecademy
codecademy.com › forum_questions › 5167ee2d2e5434778c0017d6
Css not linking to my HTML | Codecademy
<!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="mystyle.css"> </head> <body> <p>Kush is a smart person</p> </body> ... Looks fine to me. Make sure that your CSS file really has the file name “mystyle.css“ and is ...
🌐
Devpractical
devpractical.com › html-css-not-linking-properly
Why your html and css are not linking: how to link CSS to HTML properly · DevPractical
You will not be able to link HTML and CSS, if you place the <link href=""> HTML tag on any other part of the webpage other that inside the <head></head> head tags. So look at where you have placed your link HTML tag and adjust that accordingly. ... Check to make sure that your CSS file name ...
🌐
sebhastian
sebhastian.com › css-not-linking-html
How to fix CSS not linking to your HTML document | sebhastian
August 17, 2021 - Because URL can’t contain spaces, it’s recommended that you replace all spaces in your CSS file with a hyphen - or an underscore _ so that my style.css becomes my-style.css or my_style.css. The <link> tag that you used in your HTML file must be a direct child of the <head> tag as shown below:
🌐
Reddit
reddit.com › r/webdev › help needed - html + css files not linking
Help needed - HTML + CSS files not linking : r/webdev
February 2, 2024 - Open browser dev tools (f12) when ... path/linking somehow. If it loads but is not loading what is in your css file, you likely have the browser using a cached older/empty version of the css file....
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
Can't link my HTML to CSS - HTML-CSS - The freeCodeCamp Forum
October 13, 2023 - I’m new to coding and I’m doing a registration form for practice, but my CSS won’t link to my HTML. I added the link tag with rel=“stylesheet” and href=“style.css”, but it still won’t work. Also, I was having an issue with my h1 element being red for no reason, don’t know ...
🌐
Quora
quora.com › Why-is-my-CSS-not-linking-to-my-HTML-I-ve-put-link-rel-stylesheet-href-CSS-mystyle-CSS-but-it-still-will-not-work
Why is my CSS not linking to my HTML? I’ve put , but it still will not work. - Quora
Answer (1 of 2): Hi. I currently had the same issue. so I had a general folder X, where all my files are. Then I had a folder css and html for those file types respectively. Now the directories could be simplified as: desktop -> X -> css desktop -> X -> html Now if you want to acess a css file ...
🌐
Alyamanalhayekdesign
alyamanalhayekdesign.com › home › why won’t my css link to my html?
Why Won't My CSS Link to My HTML? - Alyaman Alhayek Design
February 14, 2026 - If your CSS won’t link to your HTML properly, then there may be something wrong with the path to the CSS file. According to experienced coders, if the CSS file is not saved to the same folder as the HTML, then the path to the CSS will not ...
🌐
Quora
quora.com › Why-are-my-HTML-and-CSS-files-not-linking
Why are my HTML and CSS files not linking? - Quora
Answer (1 of 18): Don’t know if this is relevant to your situation, but I discovered that a linked stylesheet and an embedded stylesheet cannot communicate. For example, I defined elements the way I wanted them and saved them as a linked stylesheet so that users could not change them. Th...
🌐
Position Is Everything
positioniseverything.net › home › css not linking to html: explaining 13 reasons and their solutions
CSS Not Linking to HTML: Explaining 13 Reasons and Their Solutions - Position Is Everything
January 15, 2019 - The wrong CSS file name is one of the root causes when your CSS fails to link to your HTML. It can take countless hours to figure out this type of error. When there is a wrong CSS file name, your HTML will consider it as a non-existent file.
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
Index.html File Won't Link to CSS File! - HTML-CSS - The freeCodeCamp Forum
May 12, 2018 - Hello folks! I’m having a weird issue with linking my index.html file to my CSS style-sheet. This has never happened befor! In my desktop text editor, when I link to my CSS style-sheet (styles.css) in my tags, everyth…
🌐
Hostinger
hostinger.com › home › tutorials › how to link css to html files in web development
How to Link CSS to HTML Files: An All-You-Need-to-Know Guide
December 16, 2025 - The most common CSS linking problems involve incorrect file paths, failure to use the proper .css file extension, and placing the <link> tag outside of the document’s <head> section. Here are the most common problems you will run into: Incorrect file path. This is the most frequent issue. Always check for case sensitivity in file names. For example, styles.css is not the same as Styles.css. Also, ensure the file is in the correct folder relative to your HTML...
🌐
GitHub
github.com › microsoft › vscode › issues › 155409
CSS not linking with HTML · Issue #155409 · microsoft/vscode
July 16, 2022 - Issue Type: Performance Issue Can you please tell me why my external style.css file is not linking to my HTML file? I have a folder called css and a file within my css folder called style.css. In the 'head' section I have a link which st...
Author   Glenda9031
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
Why is my CSS file not linking to the HTML - HTML-CSS - The freeCodeCamp Forum
December 29, 2025 - Everything is in the same file and I believe my code + structure is all correct for the most part however the css still doesn’t link to the html.