1

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

AndreaLBB
  • 21
  • 1
  • 4
  • Does this answer your question? [Where should I put the CSS and Javascript code in an HTML webpage?](https://stackoverflow.com/questions/6625773/where-should-i-put-the-css-and-javascript-code-in-an-html-webpage) – Rayees AC Sep 05 '20 at 16:28

3 Answers3

5

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>
Nikhil Singh
  • 1,486
  • 1
  • 13
  • 24
3

To import css files on html use tag link

<link rel="stylesheet" href="style.css"> // file.css

To import js files use tag script

<script src="file.js"></script>  // file.js
1

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>
wilkoklak
  • 192
  • 5