6

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??

2
  • You're right, that a good practice to split : * HTML is what I want to show * CSS is how I want to show it * Javascript is how I interact with it Commented May 4, 2016 at 10:26
  • Refer w3schools.com/html/html_css.asp Commented May 4, 2016 at 10:31

2 Answers 2

5

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.

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

Comments

1

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>

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.