Previous task
Structure of HTML page8/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 scripts

The web has the following division of roles: HTML is responsible for the structure of the document, styles are responsible for its appearance, and scripts are responsible for its behavior. With the help of scripts, for example, you can "animate" the page by adding animation and other effects. Scripts are created using the JavaScript language.

Scripts are attached in the same way as styles: they are either written inside the page or attached as external files.

Embedded scripts are written inside the <script> tag. For example:

<script>
  JavaScript code
</script>

The <script> tag can be used anywhere in the HTML document, but it is better to insert it at the very end, before the closing </body> tag.

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Connecting scripts</title> <link rel="stylesheet" href="style.css"> </head> <body> <h1>Connecting scripts</h1> <p class="blinking">You can connect scripts in a number of ways. One way is to describe scripts directly inside the HTML page.</p> <!-- <script> let p = document.querySelector(".blinking"); setInterval(function() { p.classList.toggle("big-font"); }, 2000); </script> --> </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; } .big-font { font-size: 24px; line-height: 36px; } p { transition: font-size 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
    1. Uncomment the <script> tag.

    © 2023-2024, codehero.pro