- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
JavaScript is a powerful programming language used to make web pages interactive and dynamic. It can be integrated into HTML in two main ways: inline within the HTML document or as an external file.
Inline JavaScript
To add JavaScript code directly within an HTML document, you use the <script> tag. This tag can be placed in either the <head> or <body> section of your HTML document, depending on when you want the JavaScript to execute.
Example in the <head> Section
If you want the JavaScript to run before the rest of the page loads, place the <script> tag in the <head> section:
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Today's Date</title><script>let d = new Date();alert("Today's date is " + d);</script></head><body></body></html>Copied!✕CopyExample in the <body> Section
If you want the JavaScript to run at a specific point within the page layout, place the <script> tag in the <body> section:
Add JavaScript to your web page - HTML | MDN - MDN Web Docs
Sep 11, 2025 · Take your webpages to the next level by harnessing JavaScript. Learn in this article how to trigger JavaScript right from your HTML documents.
HTML JavaScript - GeeksforGeeks
Jan 17, 2026 · JavaScript is added to an HTML document using the <script> tag to enable interactivity and dynamic behavior. JavaScript can be written directly inside the HTML file. An external .js file can …
Master Javascript | Beginner Javascript | Learn by Doing
Sponsored Take your skills to a new level and join millions of users that have learned Javascript. Learn key takeaway skills of Javascript and earn a certificate of completion.HTML Development Course - HTML, CSS, & JavaScript
Sponsored Learn the essentials with the IBM Full Stack Software Developer Professional Certificate. Prepare for new roles with the IBM Full Stack Software Developer Professional Certificate.Best JavaScript IDE | WebStorm, a JetBrains IDE
Sponsored Enjoy more productive JavaScript development with WebStorm. Ready to use out of the box. No plugin configuration required. Try it now for free!