How to include JavaScript File in HTML5 ?
Last Updated :
29 Jan, 2024
In HTML5, we can include external scripts using the <script>
element. External scripts are commonly used to link JavaScript files or other script files hosted externally. Here’s how you can include external scripts in HTML5.
Link the External Script in HTML
To link an external script in HTML, use the <script>
tag with the src
attribute pointing to the external JavaScript file.
Syntax
<body>
<h1>My Web Page</h1>
<!-- External JavaScript -->
<script src="script.js"></script>
</body>
Link the Internal Script in HTML
To include an internal (inline) script directly within the HTML document, use the <script>
tag without the src
attribute
Syntax
<script>
// Your JavaScript code goes here
console.log("Hello, World!");
</script>
Share your thoughts in the comments
Please Login to comment...