3 min read · Free · No login needed
JavaScript is the programming language of the web. HTML builds the page, CSS styles it, and JavaScript makes it do things: respond to clicks, check a form before it is sent, show and hide content, load new data without refreshing the page.
Write it inside a <script> tag, usually just before the closing </body> so the page content loads first. Or keep it in a separate .js file and link it: <script src="app.js"></script>. The separate-file way is better for real sites — one script file can serve every page.
document.getElementById("demo").innerHTML = "Hello!"; replaces the text inside an element.element.style.color = "red"; recolours it.The example below has a button. When you click it, JavaScript changes the text of a paragraph. It is only three lines — but it is the same idea behind every interactive feature on the web, from a "like" button to a full quiz timer.
JavaScript is the programming language of the web. HTML builds the page, CSS paints it, and JavaScript makes it do things — respond to clicks, check a form before it is sent, load new data without reloading the page. It runs in the browser, on the visitor's computer, and every modern website uses it.
JavaScript goes inside a <script> tag. Put the tag at the end of the <body>, so the HTML loads first and the script can find the elements it needs:
<p id="demo">Hello.</p>
<script>
document.getElementById("demo").innerHTML = "Hello, JavaScript!";
</script>
This short script finds the paragraph with id="demo" and replaces its text. When the page loads, the visitor sees "Hello, JavaScript!" instead of "Hello."
<script> in the <head> runs before the page body exists, so it cannot find your elements yet. That is why scripts usually go at the end of the body — or use the defer attribute, which tells the browser to wait until the page is ready.document.title and press Enter.</script> — the rest of the page is then treated as script and disappears.<p id="demo"> — the paragraph JavaScript will change. The id gives it a name the script can find.<button onclick="..."> — the onclick attribute says "when this button is clicked, run this JavaScript".document.getElementById('demo') — finds the paragraph by its id, like looking someone up by name..innerHTML = 'Hello, JavaScript!' — replaces the text inside the paragraph with the new message, instantly, without reloading the page.<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
</head>
<body>
<p id="demo">Click the button to change this text.</p>
<button onclick="document.getElementById('demo').innerHTML = 'Hello, JavaScript!'">Click Me</button>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
It is the programming language of the web; HTML builds the page, CSS styles it, and JavaScript makes it do things like respond to clicks.
At the end of the body, so the HTML loads first and the script can find the elements it needs.
It finds nothing and silently does nothing, so scripts usually go at the end of the body or use the defer attribute.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →