HTML and CSS Certification 2025 – 400 Free Practice Questions to Pass the Exam

Image Description

Question: 1 / 400

What is the correct way to link to an external JavaScript file in HTML?

<script href="script.js"></script>

<link src="script.js" rel="script">

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

Linking to an external JavaScript file in HTML is achieved using the `<script>` element with the `src` attribute. This is the standard and correct method for including an external JavaScript file into an HTML document. When using this tag, the browser knows to fetch and execute the JavaScript file specified by the `src` attribute.

Using `<script src="script.js"></script>` correctly sets the path to the JavaScript file, allowing it to be loaded into the HTML page. This enables you to separate your JavaScript code from your HTML, promoting cleaner code structure and easier maintenance.

The other methods used in the question are not suitable for linking to JavaScript. The first option incorrectly uses the `href` attribute, which is meant for the `<link>` tag typically used for stylesheets. The second option uses the `<link>` tag with incorrect attributes; `<link>` is used for including stylesheets rather than scripts. The last option, `<import>`, is not a valid HTML tag for including JavaScript. Therefore, the right method is the one that correctly utilizes the `<script>` tag with the `src` attribute.

Get further explanation with Examzify DeepDiveBeta

<import src="script.js">

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy