0

I have written a HTML code and CSS code in Notepad++. I have linked my CSS code in the below way. After saving both of the files in the same directory, I am running both of the files by double clicking them. I can see my HTML running properly in the browser. Although, when I am trying to run my CSS file, it just opens in Notepad. I have saved my CSS file as 'all type files' named as style1.css

Code for HTML:

<!doctype html>
<html lang ="en">
<head>
<meta charset = "utf-8">
<title>HTML CSS COURSE </title>
<link rel ="stylesheet" type ="text/css" href ="style1.css">
</head>
<style>

</style>
<body>
Hello World!
</body>
</html>

****Code for CSS:****

body{

background-color:red;

}
1
  • 1
    NO need to run CSS file through browsers like localhost/filename.css you will run HTML files like localhost.html and CSS will be included in your HTML file Commented Nov 3, 2019 at 10:04

1 Answer 1

0

You must add the code within the style block if you want to apply it internally. If you want to apply an external CSS, then just add the link in the Head block.

Internal way

<!doctype html>
<html lang ="en">
<head>
<meta charset = "utf-8">
<title>HTML CSS COURSE </title>
</head>
<style>
body{

background-color:red;

}
</style>
<body>
Hello World!
</body>
</html>

External way

<!doctype html>
<html lang ="en">
<head>
<meta charset = "utf-8">
<title>HTML CSS COURSE </title>
<link rel ="stylesheet" ref ="style1.css">
</head>
<body>
Hello World!
</body>
</html>

Make sure both html and css files are in same folder.

Good luck

Not the answer you're looking for? Browse other questions tagged or ask your own question.