Unit 8: Web Development with HTML, CSS and JavaScript

Class 9 Computer Science · Punjab Board · Session 2026-27 · PECTAA syllabus

Smart Syllabus 2027: some topics of this unit are removed — study the full chapter, but check the official PECTAA smart syllabus for the 2027 paper.

Web development means building websites that people can open in a browser. A web page has three main parts: HTML gives it structure, CSS gives it style and colour, and JavaScript makes it interactive. In this chapter we learn the basic tags of HTML, the basic properties of CSS, and the basic ideas of JavaScript.

Introduction to Web Development and HTML

A website is made of web pages, and each page is a file that a browser opens and displays. HTML, which stands for HyperText Markup Language, is the language used to create the structure and content of a web page. It uses tags to mark different parts of the page, such as headings, paragraphs, links, and images. An HTML document starts with <html> and contains two main parts: the <head> section, which holds information about the page such as its title, and the <body> section, which holds the content shown to the user. The title is written inside the <title> tag in the head section, and it appears in the browser tab.

Basic HTML Tags

The most common HTML tags are easy to learn. Headings are made with <h1> to <h6>, where <h1> is the largest and <h6> is the smallest. A paragraph is made with the <p> tag. A link is made with the <a> tag and the href attribute, for example <a href="https://example.com">Visit</a>. An image is added with the <img> tag, which uses the src attribute for the image address and the alt attribute for text shown if the image cannot load. A list with bullets is made with <ul>, and a numbered list is made with <ol>, with each item inside <li>. Some tags, such as <p> and <h1>, need a closing tag, while <img> does not need one.

Styling a Web Page with CSS

CSS stands for Cascading Style Sheets. It is used to control how a web page looks, including colours, fonts, sizes, spacing, and layout. Without CSS, a page looks plain. A CSS rule has three parts: a selector, a property, and a value. For example, in p { color: blue; }, p is the selector, color is the property, and blue is the value. Common properties are color for text colour, background-color for background colour, font-size for the size of text, font-family for the type of font, and text-align for the alignment of text. CSS can be written inside the <style> tag in the head section of an HTML page, which is called internal CSS, or in a separate file, which is called external CSS.

Making a Web Page Interactive with JavaScript

JavaScript is a programming language that makes a web page interactive. With JavaScript, a page can respond when a user clicks a button, types in a form, or moves the mouse. A variable is used to store a value, and it is created with let or const, for example let name = "Ali";. A function is a block of code that runs when it is called, for example when a button is clicked. To change something on a page, JavaScript first selects an HTML element, often with document.getElementById("id"), and then changes its text or style. JavaScript code is usually written inside a <script> tag at the end of the body section of an HTML page.

How HTML, CSS, and JavaScript Work Together

A simple web page combines all three languages. HTML gives the structure, such as a heading, a paragraph, and a button. CSS gives the style, such as the colour and size of the heading and the button. JavaScript gives the action, such as showing a message when the button is clicked. For example, a button can call a JavaScript function that changes the text of a paragraph. This is how real websites work: the three languages work together on every page. When building a page, it is good practice to keep the structure, style, and code tidy so the page is easy to read and easy to fix.

Good Practices for Web Pages

Good web pages are easy to read, easy to use, and work well on different screen sizes. Headings should be used in order, from <h1> down, and every image should have an alt text so the page is useful even when the image does not load. Links should have clear text that tells the user where the link goes. Colours should be easy to read, with good contrast between text and background. Comments in HTML, written as <!-- comment -->, are not shown on the page and are used to explain the code to other people who read it.

Key definitions

TermDefinition
HTMLThe standard language used to create the structure and content of a web page, using elements written with tags.
CSSA language used to control the style and appearance of a web page, such as colours, fonts, spacing, and layout.
JavaScriptA programming language used to make web pages interactive, for example by responding to a button click or checking a form.
TagA word or symbol in angle brackets, such as <p> or <h1>, used to mark the start or end of an HTML element.
AttributeExtra information added to an HTML tag, for example href in <a href="https://example.com">, which gives the link address.
BodyThe part of an HTML document that contains the content shown to the user, such as headings, paragraphs, images, and links.
HyperlinkAn HTML element used to create a clickable link to another page or website, written with the <a> tag and the href attribute.

Important points

  • HTML stands for HyperText Markup Language and is used to create the structure of a web page.
  • CSS stands for Cascading Style Sheets and is used to style a web page.
  • JavaScript is used to make web pages interactive.
  • An HTML document starts with <html> and has a <head> section and a <body> section.
  • <h1> is the largest heading and <h6> is the smallest heading.
  • <p> is used for a paragraph and <a href="..."> is used for a link.
  • <img> is used to add an image and <ul> is used for an unordered, bulleted list.
  • In CSS, the color property sets text colour and font-size sets the size of text.
  • In CSS, background-color sets the background colour and text-align sets the alignment of text.
  • In JavaScript, a variable is created with let or const, and document.getElementById() is used to select an HTML element by its id.
  • In HTML, <!-- --> is used to write a comment that is not shown on the page.
  • A CSS rule has a selector, a property, and a value, for example p { color: blue; }.
  • The <title> tag inside the <head> section sets the title shown in the browser tab.
  • A JavaScript function is a block of code that runs when it is called, for example when a button is clicked.

MCQs — test yourself

1. What does HTML stand for?

  1. HyperText Markup Language
  2. HighText Machine Language
  3. Hyperlink Text Markup Language
  4. Home Tool Markup Language
Show answer

Answer: A — HyperText Markup Language. HTML stands for HyperText Markup Language.

2. CSS is used to:

  1. Structure a web page
  2. Store data in a database
  3. Style a web page
  4. Make a web page interactive
Show answer

Answer: C — Style a web page. CSS is used to control the style, colours, fonts, and layout of a web page.

3. Which language is used to make a web page interactive?

  1. HTML
  2. JavaScript
  3. CSS
  4. HTTP
Show answer

Answer: B — JavaScript. JavaScript adds interactivity, such as responding to clicks and checking forms.

4. Which tag is used to create a paragraph?

  1. <h1>
  2. <a>
  3. <img>
  4. <p>
Show answer

Answer: D — <p>. The <p> tag creates a paragraph.

5. Which is the largest heading tag in HTML?

  1. <h1>
  2. <h3>
  3. <h6>
  4. <h2>
Show answer

Answer: A — <h1>. <h1> is the largest heading tag and <h6> is the smallest.

6. Which tag is used to create a hyperlink?

  1. <p>
  2. <img>
  3. <a href>
  4. <ul>
Show answer

Answer: C — <a href>. The <a> tag with the href attribute creates a link to another page or website.

7. Which CSS property sets the colour of text?

  1. font-color
  2. color
  3. text-color
  4. background-color
Show answer

Answer: B — color. The color property in CSS sets the colour of text.

8. Which is the correct way to add an image in HTML?

  1. <img src="photo.jpg" alt="A photo">
  2. <img link="photo.jpg">
  3. <image src="photo.jpg">
  4. <pic src="photo.jpg">
Show answer

Answer: A — <img src="photo.jpg" alt="A photo">. The src attribute gives the address of the image file, and alt gives text if the image does not load.

9. Which keyword is used to declare a variable in JavaScript?

  1. varies
  2. integer
  3. let
  4. string
Show answer

Answer: C — let. In JavaScript, let and const are used to declare a variable.

10. Which JavaScript code selects an element by its id?

  1. getElement()
  2. document.getElementById()
  3. selectId()
  4. findElement()
Show answer

Answer: B — document.getElementById(). document.getElementById() selects the HTML element with the given id.

Short questions

1. What is HTML? What is it used for?

HTML stands for HyperText Markup Language. It is used to create the structure and content of a web page, using tags for headings, paragraphs, links, images, and lists.

2. What is CSS? What is it used for?

CSS stands for Cascading Style Sheets. It is used to control the appearance of a web page, such as colours, fonts, text size, spacing, and layout. A CSS rule has a selector, a property, and a value.

3. What is a hyperlink? How is it created in HTML?

A hyperlink is a clickable link that takes the user to another page or website. It is created with the <a> tag and the href attribute, for example <a href="https://example.com">Visit Website</a>.

4. Which CSS properties are used to set text colour and background colour? Give an example.

In CSS, the color property sets the colour of text and the background-color property sets the background colour. For example, p { color: blue; background-color: yellow; } makes paragraph text blue on a yellow background.

5. What is JavaScript? Give one example of what it can do on a web page.

JavaScript is a programming language used to make web pages interactive. For example, it can show a message when a button is clicked, check a form before it is sent, or change the text on a page. It is written inside a <script> tag.

Summary

HTML gives a web page its structure, CSS gives it style, and JavaScript makes it interactive. Headings, paragraphs, links, images, and lists are made with HTML tags, while colour, font size, and layout are controlled with CSS properties. JavaScript uses variables and functions to respond to the user, for example when a button is clicked. Together, the three languages make a complete and useful web page.

← Back to Class 9 Computer Science chapter list