Previous task
Structure of HTML page9/10
Back to the list of tasks
  1. 1. Where HTML begins
  2. 2. The simplest HTML page
  3. 3. HTML page title
  4. 4. HTML page encoding
  5. 5. Connecting styles
  6. 6. Connecting external styles
  7. 7. The mystery of the CSS editor
  8. 8. Connecting scripts
  9. 9. Connecting external scripts
  10. 10. Connecting external styles and scripts again
Nest task
  • Courses
  • Sign up
  • Log in

Loading...
It will be ready in a few seconds.

  • Theory
  • Theory

Connecting external scripts

Scripts are most often connected from external files with the extension .js. To do this, use the <script> tag with the src attribute, which specifies the path to the file. For example:

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

Note that the <script> tag is paired. If you connect external scripts, just don't write anything inside the tag.

It is better to connect external scripts before the closing </body> tag.

In this assignment, you will plug in an external script, which is located at: external.js(follow the link to open this file in your browser).

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Connecting external scripts</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>External scripts</h1> <p>External scripts, like external styles, are used much more often than inline scripts.</p> <p>It's easier to make changes to them, especially when the same script is connected to a large number of pages.</p> <p>And external resources are also cached by the browser, making pages load faster. And in the web, that's important.</p> <!-- connect an external script here --> </body> </html>
CSS
body { margin: 20px; font-size: 18px; line-height: 24px; } h1 { font-size: 52px; line-height: 64px; font-family: "Monaco", "Courier", monospace; color: #618ad2; transition: color 0.5s; }

The code has changed, click "Update" or enable autorun.

You have moved to another page

Click inside the mini-browser to highlight this window.

100%
GoalsCompleted
0

    Connect an external script to the page. To do this:

    1. Before the closing </body> tag, insert the <script></script> tag.,
    2. then add a src attribute to it with the value external.js.

    © 2023-2024, codehero.pro