Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate html code from css code

Tags:

html

css

I have a file containing both html and css code.How it is possible to separate the html code in some files and css in some other files??

like image 280
stones Avatar asked May 04 '16 10:05

stones


2 Answers

Yes. You can save the css in a .css file. Then in your HTML head tags, you can do <link rel='stylesheet' href='yourcssfile.css'>

<html>
  <head>
    <link rel='stylesheet' type='text/css' href='yourcssfile.css'>
  </head>
  <body>
    <p>Test</p>
  </body>
</html>

In yourcssfile.css

p {
  color:red;
}

This will make the paragraph text red and your CSS is within a different file.

like image 74
Albzi Avatar answered Sep 28 '22 07:09

Albzi


Simply put the CSS code into a file.css and include it in your HTML file.

<head>
<link rel="stylesheet" type="text/css" href="file.css">
</head>
like image 41
Danny Cullen Avatar answered Sep 28 '22 06:09

Danny Cullen