Lesson goal: Explain how HTML, CSS, and JavaScript work together.
A web page often uses three technologies together: Web page technologies. These elements create a cohesive user experience because they serve distinct purposes.
| Technology | Main purpose | Student profile example |
|---|---|---|
| HTML | Organises content and gives it meaning | Adds the student’s name and course |
| CSS | Controls presentation | Sets colours, spacing, and font sizes |
| JavaScript | Adds programmed behaviour | Prints a welcome message or updates information |
Let us look at each part.
HTML uses tags to describe content. These tags tell the browser how to display elements on the page.
<h1>Student Profile</h1>
<p>Name: Aman Singh</p>
<p>Course: JavaScript Basics</p>
In this example:
<h1> marks the main heading.<p> marks a paragraph.</p>, mark the end of an element.The browser displays the heading and paragraphs on the page, making it readable. Therefore, HTML serves as the foundation for any web page.
CSS uses rules to style HTML elements. This includes adjusting colors and layout. For example, CSS can make a web page visually appealing.
h1 {
color: navy;
}
p {
font-size: 18px;
}
Here:
h1 selects the main heading.color: navy; changes its text colour.p selects the paragraphs.font-size: 18px; sets their text size.The content remains the same, but its appearance changes based on the CSS rules. Thus, CSS and HTML work in tandem to enhance user experience.
JavaScript adds interactivity by running instructions on the page. As a result, it allows developers to create dynamic web pages.
console.log("Welcome, Aman Singh!");
This code prints a welcome message in the console. Next, you will use JavaScript to change the page itself. Console output lets us confirm that our code runs correctly.
For a project, we will use three files:
| Filename | What it contains |
|---|---|
index.html |
Page content and links to the other files |
style.css |
Styling rules |
script.js |
JavaScript instructions |
The HTML file connects the other two files to the page, allowing them to work together. Therefore, understanding this connection is crucial for web development.
Changing a name in HTML does not automatically change a name written separately in JavaScript. For example, if the HTML shows “Aman” and the JavaScript says “Simran,” the browser uses both exactly as written. Consequently, it is important to keep names consistent across files.
Your turn
Choose the most suitable technology for each task:
Answers: 1. HTML, 2. CSS, 3. JavaScript, 4. HTML.
HTML describes content, CSS styles it, and JavaScript runs instructions. A small project becomes easier to manage when each has its own file. As a result, maintaining the code is much more efficient.