98 of 133 menu

The script tag

The script tag includes JavaScript to the HTML page (and, much less frequently, other scripts).

You can include a separate JavaScript file (in this case, the src attribute must be specified) or write JavaScript directly on the HTML page. In fact, script behaves like the link tag and the style tag at the same time, only not for CSS, but for JavaScript.

This tag should be placed inside the head tag, but this is not necessary - the script tag can be placed inside the body tag and it will work.

Attributes and properties

Attribute/property Description
src Path to the included file.
type The data type of the file to include. For JavaScript, use text/javascript. This is not required in HTML5.
language Specifies the script language. This attribute is deprecated and the type attribute should be used instead.
defer The defer attribute delays script execution until the entire page has been fully loaded.

Example

Let's include a separate JavaScript file:

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

Example

And so we will write JavaScript code directly on the HTML page:

<script> let test = '123'; </script>

See also

byenru