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.cssexists 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.
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.cssexists 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.
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.
Videos
Why is my CSS file not affecting my HTML?
How do I link a CSS file to an HTML file in a different folder?
Can I use multiple CSS files for one HTML page?
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
hrefwithsrc- still nothing happens.
Appreciate any help!
I invite you to read this article Absolute and Relative Paths
Then we pass to your code:
<link rel="stylesheets" type="text/css" href="/styles.css">
Should be :
<link rel="stylesheet" type="text/css" href="styles.css">
Your styles.css should be in the same folder as your html file.
To verify that you have an error , check Console of your browser,you will be noticed that your file doesn't exist(404 error).
An other way to make your css working is to integrate it inside your page without separation:
Example:
<style type='text/css'>
body {
background-color:#CCCCCC;
}
h1 {
color:#0000EE;
}
</style>
If the other suggestions don't work, you can try re-saving the HTML and CSS sheets with "UTF-8" encoding and declare UTF-8 encoding in the HTML under the <head> with <meta charset="utf-8>"
hello Im a beggienrto web dev. As you can see my css folder and my HTML_Personal Site folder are both under the Web Development Folder and i made the path within the link tag. None of my external css code is being applied to my html page. Thanks in advance!
Your CSS folder needs to be in the HTML_Personal_Site folder.
Edit to expand: Your index.html file resides in your HTML_Personal_Site folder so that's where it begins the search in your path. Currently it's looking for a folder named CSS within HTML_Personal_Site. If you wanted to keep your CSS folder where it's at for some reason, you'd add ../, which denotes moving a level up in your file architecture, to your current path to give you ../css/styles.css.
Your index file is in the personal site directory, you would need to have it as
../css/stylesheet.css
This exits out of the directory and into the css directory