Last updated: 4 December 2026 · Punjab Board 9th Class Computer Science and Entrepreneurship (new syllabus 2025-26) · Unit 8
Easy, exam-focused notes for Unit 8: Web Development with HTML, CSS and JavaScript of the new Punjab Board 9th class Computer Science book. Short answers are written to fit the board e-sheet answer space. All exercise MCQs are checked against the textbook answer key.
In this unit
- Web development: front-end, back-end, full-stack
- HTML: history, structure and tags
- Headings, paragraphs, links, images, lists, tables, comments
- CSS: syntax, 3 ways, fonts, backgrounds, layouts
- CSS animations and transitions
- JavaScript: variables, data types, functions, events
- Debugging and testing
- Exercise: MCQs, short and long questions
- FAQs
8.1–8.2 Web development
Web development is the process of creating websites and web applications using programming languages and tools. Why learn it: digital literacy, career opportunities, problem solving, creativity and entrepreneurship (e.g. a website to sell your crafts).
| Type | Deals with | Technologies |
|---|---|---|
| Front-end | What users see and interact with | HTML (structure/skeleton), CSS (style/look), JavaScript (interactivity) |
| Back-end | Behind the scenes: servers, databases, logic | Web servers, databases, PHP, Python, Ruby |
| Full-stack | Both front-end and back-end | Example: a login page (front) + checking the password in a database (back) |
8.3–8.4 HTML basics
HTML (HyperText Markup Language) is the standard language for creating web pages; its tags are like LEGO blocks. Created by Tim Berners-Lee in 1991. Versions: HTML 1.0 (1991), 2.0 (1995), 3.2 (1997, tables/scripts), 4.0 (1997, multimedia), 4.01 (1999), HTML5 (2014).
Tools: a text editor (Notepad, Notepad++, Sublime Text, VS Code) to write code, and a browser (Chrome, Firefox, Edge) to view it. Save the file with the .html extension (e.g. my_first_website.html) and open it in a browser; refresh after every change.
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first web page.</p>
</body>
</html>
| Part | Purpose |
|---|---|
| <!DOCTYPE html> | Tells the browser this is an HTML5 document |
| <html> | Root element of the page |
| <head> | Information about the page (title, CSS links, meta) |
| <title> | Text shown in the browser tab |
| <body> | Everything visible on the page |
| <h1> | Main heading |
| <p> | Paragraph |
Paired tags have an opening and closing tag: <p>…</p>. Unpaired (self-closing) tags have no closing tag: <img>, <br>, <hr>.
8.5 Creating content with HTML
| Element | Code | Note |
|---|---|---|
| Headings | <h1> … <h6> | h1 = main title, h2–h6 smaller subheadings; help organisation, SEO and consistent formatting |
| Paragraph | <p>Text</p> | Block of text with space above and below |
| Link | <a href="https://www.example.com">Visit</a> | href gives the address; mailto: opens email |
| Image | <img src="image.jpg" alt="description"> | alt text helps visually impaired users |
| Unordered list | <ul><li>Item</li></ul> | Bullets |
| Ordered list | <ol><li>Item</li></ol> | Numbers |
| Table | <table><tr><th>Name</th></tr><tr><td>Ali</td></tr></table> | tr = row, th = header cell, td = data cell |
| Horizontal line | <hr> | Unpaired tag |
| Comment | <!– This is a comment –> | Not shown by the browser; used for notes or disabling code |
| Division | <div> … </div> | Groups elements so they can be styled together |
8.6 Styling with CSS
CSS (Cascading Style Sheets) controls colours, fonts, layout and design, keeping content (HTML) separate from presentation. A CSS rule has a selector and declarations: selector { property: value; }
h1 {
color: red;
font-size: 24px;
}
| Way | How | Use |
|---|---|---|
| Inline | <h1 style="color: blue;">Hello</h1> | Quick change to one element; gets messy |
| Internal | <style> h1 { color: yellow; } </style> in the head | Styles one whole page |
| External | <link rel="stylesheet" href="styles.css"> in the head | Best for big sites; one file styles many pages |
- Fonts: font-family (Arial, sans-serif), font-size (16px), font-weight (bold), font-style (italic).
- Backgrounds: background-color, background-image: url(“pic.jpg”), background-repeat, background-position: center, background-size: cover.
- Layouts: group content with div and section; CSS Grid (display: grid; rows and columns); Flexbox (display: flex; items in a row or column); positioning (position: absolute; top; left).
- Box model: every element is a box – content, then padding (space inside the border), border, then margin (space outside the border).
Selectors: element selector (p), class selector (.box), id selector (#main), and pseudo-classes like :hover.
8.6.5 Animations and transitions
@keyframes example {
from { background-color: red; }
to { background-color: yellow; }
}
.animated-box {
width: 100px; height: 100px;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
.box { width: 100px; background-color: red;
transition: background-color 2s, width 2s; }
.box:hover { background-color: yellow; width: 200px; }
Animation uses @keyframes to change styles over time (can loop). Transition changes a property smoothly when its state changes, e.g. on hover.
8.7 JavaScript
JavaScript makes web pages interactive (pop-ups, buttons, games). Created by Brendan Eich in 1995 in 10 days (first called Mocha, then LiveScript). It is written inside <script> tags or in a separate file linked with <script src="script.js"></script>.
<script>
var name = "Athar";
var age = 15;
alert("Name: " + name + ", Age: " + age);
</script>
Variables are declared with var, let or const. Comments: // single line and /* multi-line */.
| Data type | Example |
|---|---|
| String (text, in quotes) | var name = “Athar”; |
| Number | var age = 15; |
| Boolean | var isStudent = true; |
| Array | var scores = [90, 85, 88]; |
function addNumbers(a, b) {
var sum = a + b;
alert("The sum is: " + sum);
}
addNumbers(5, 3); // shows "The sum is: 8"
| Event | Happens when |
|---|---|
| onclick | An element is clicked |
| onload | Page or image finishes loading |
| onmouseover | Mouse moves over an element |
| onmouseout | Mouse leaves an element |
| onkeyup | A key is released |
<button onclick="showMessage()">Click Me!</button>
<script>
function showMessage() { alert("Button was clicked!"); }
</script>
8.8 Debugging and testing
- Browser developer tools: use the console (console.log) to see values and errors.
- Read error messages and check code line by line for missing semicolons, unmatched braces, wrong names.
- Common issues: broken links, wrongly nested or unclosed tags, CSS typos.
- Testing: cross-browser testing (Chrome, Firefox, Edge), responsive testing (phone, tablet, desktop) and user testing.
Unit 8 exercise (solved)
A. Multiple choice questions
1. Which of the following is not a correct HTML tag?
(a) <div> (b) <span> (c) <head> (d) <footer>
Answer: (d) <footer> – Answer as per the textbook key. Note:
2. What does CSS stand for?
(a) Cascading Style Sheets (b) Computer Style Sheets (c) Creative Style Sheets (d) Colorful Style Sheets
Answer: (a) Cascading Style Sheets – CSS styles web pages.
3. Which of the following tag is used to create a hyperlink in HTML?
(a) <link> (b) <a> (c) <href> (d) <nav>
Answer: (b) <a> – href is an attribute of .
4. Which property is used to change the background color in CSS?
(a) color (b) background-color (c) bgcolor (d) background
Answer: (b) background-color – color changes the text colour.
5. Which HTML attribute is used to define inline styles?
(a) class (b) style (c) font (d) styles
Answer: (b) style – e.g. style=”color: blue;”
6. Which of the following is the correct syntax for a CSS rule?
(a) selector {property: value;} (b) selector: {property=value;} (c) selector {property=value} (d) selector: {property: value;}
Answer: (a) selector {property: value;} – Colon between property and value, semicolon at the end.
7. In JavaScript, which markup is used for comments?
(a) /**/ (b) // (c) <– (d) /* */
Answer: (b) // – // for one line (/* */ for several lines).
8. How do you include JavaScript in an HTML document?
(a) <script src="script.js"></script> (b) <java src="script.js"></java> (c) <js src="script.js"></js> (d) <code src="script.js"></code>
Answer: (a) <script src="script.js"></script> – Only the script tag runs JavaScript.
9. Which HTML tag is used to create an unordered list?
(a) <ol> (b) <ul> (c) <li> (d) <list>
Answer: (b) <ul> –
- is the ordered list.
- HTML – structure and content (skeleton): headings, paragraphs, images, links.
- CSS – presentation (looks): colours, fonts, layout, animations.
- JavaScript – behaviour (interactivity): responds to clicks, forms, changes content.
- Together they make a complete front-end.
- Install a text editor (Notepad++, Sublime Text, VS Code).
- Install browsers (Chrome, Firefox, Edge) to test.
- Create a folder; save files as .html, .css, .js.
- Open the HTML file in the browser; refresh after changes; use developer tools (console) for debugging.
- Element:
p { color: blue; }– all paragraphs. - Class:
.box { padding: 10px; }– elements with class=”box”. - ID:
#header { background: grey; }– the one element with id=”header”. - Group:
h1, h2 { color: red; }. - Pseudo-class:
a:hover { color: green; }– when the mouse is over a link. - Add
<meta name="viewport" content="width=device-width, initial-scale=1.0">. - Use flexible units (%, not fixed px widths) and flexbox/grid.
- Use media queries, e.g.
@media (max-width: 600px) { .container { display: block; } }so columns stack on phones. - Test in the browser’s responsive design mode.
- Animation: define
@keyframes(from/to steps), then apply withanimation-name,animation-duration,animation-iteration-count(e.g. infinite) andanimation-timing-function(e.g. linear). - Transition: set
transition: property time;on the element and give a new style in a state like:hover; the change happens smoothly. See the examples above.
10. Which tag is used to display a horizontal line in HTML?
(a) <br> (b) <hr> (c) <line> (d) <hline>
Answer: (b) <hr> –
is a line break.
B. Short questions
/* main heading style */. The browser ignores it.