I'm working on a small website project using HTML, CSS, and JavaScript. So I followed the tutorial, but now that I have a .html file, a .css file and a .js file I don't know how to make them work together. Sorry for the silly question, but I really need to know how to link the .css file and the .js file in the .html file. Thanks
3 Answers
To link CSS - <link rel="stylesheet" href="styles.css">
To link JS - <script src="myscripts.js"></script>
Your HTML document would look like this -
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Title of your HTML page</title>
</head>
<body>
<!-- Put your HTML here -->
<script src="myscripts.js"></script>
</body>
</html>
Comments
Generally speaking, you want to put your CSS (stylesheet) in you <head> tag.
For example:
<head>
<link rel="stylesheet" href="path_to_css.css" />
</head>
Speaking of scripts, nowadays I think browsers load JavaScript in parallel, so it doesn't make a big difference, but from what I've learned in the past - putting javascript just before the end of the <body> tag is a good practice.
<body>
... your HTML content here
...
<script src="path_to_js.js" />
</body>