HTML JavaScript

Make pages interactive with the script element.

✍️ 3 exercises + code challenge in this lesson

JavaScript makes HTML pages dynamic and interactive. Add it with the <script> element, either inline or from a file with src="app.js".

A common first step is to find an element with document.getElementById() and change its content or style.

The noscript element

<noscript> shows content only to users who have JavaScript turned off.

Learn more in the JavaScript tutorial.

Key Takeaways: HTML JavaScript

Mastering HTML JavaScript helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

HTML JavaScript Code Example

HTML
<p id="clock">Click the button to see the time.</p>
<button onclick="showTime()">What time is it?</button>

<script>
  function showTime() {
    document.getElementById("clock").innerHTML = "It is " + new Date().toLocaleTimeString();
  }
</script>
<noscript>Please enable JavaScript.</noscript>
Free sign-in required · Google login available

HTML JavaScript Practice Exercises

Check what you learned in “HTML JavaScript”.

/ 3 solved
Fill in the blank

Insert the element that holds JavaScript code.

<>
  document.write('Hi');
</>
✓ Correct! Not quite. Try again.
Multiple choice

Which method finds an element by its id?

✓ Correct! Not quite. Try again.
Code challenge

Use JavaScript to change the paragraph text to "Changed!".

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services