how to link javascript to html – Code Example

In this article we will give you code to add javascript to html. Also we will show you code to link external javascript files in your html code.

Code Example –

1. Add javascript to html

<!DOCTYPE HTML>
<html>
  <head>
    <script>
       // Add your javascript here
    </script>
  </head>

  <body></body>
</html>

2. Link external javascript file to html

<!DOCTYPE HTML>
<html>
  <head>
    <script src= "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  </head>

  <body></body>
</html>

3. Link local javascript file to html

<!DOCTYPE HTML>
<html>
  <head>
    <script src="/absolute_file_path.js"></script>
  </head>

  <body></body>
</html>