Computer Science · Chapter 3
Study notes aligned to the official NEB syllabus.
In Grade 11 we learned to structure a web page with HTML. HTML alone, though, gives a plain and static page. Real websites are styled so they look attractive, they respond when the user clicks or types, and they remember data and talk to databases on a server. This chapter adds those three abilities: CSS to control how a page looks, JavaScript to make the page behave and react in the browser, and PHP to run logic and connect to a database on the server. Together with HTML these turn a flat document into a working web application.
The Internet is the global network of interconnected computers that communicate using the TCP/IP protocol suite. Running on top of it is the World Wide Web (WWW), the collection of linked web pages identified by URLs and delivered using HTTP (HyperText Transfer Protocol). When you type a web address, your browser (the client) sends an HTTP request to a web server, and the server responds with the requested page. A URL (for example https://example.com/index.html) names the protocol, the server (domain) and the resource on it. Understanding this request and response cycle is the key to understanding where each technology in this chapter runs.
Web scripts run in one of two places, and knowing which is essential.
Client side scripting runs inside the user's browser, after the page has been downloaded. It handles things that concern the look and immediate behaviour of the page, such as validating a form, showing or hiding content, and responding to clicks, without contacting the server again. JavaScript is the main client side language (with CSS controlling appearance). It is fast for the user and reduces load on the server, but the code is visible to the user and cannot be trusted for security.
Server side scripting runs on the web server before the page is sent to the browser. It handles work that must happen on the server, such as reading and writing a database, checking passwords and generating pages dynamically. PHP is a common server side language. It can keep secrets and access data safely, but every request must travel to the server, so it is comparatively slower for pure interface tasks.
| Basis | Client side (JavaScript) | Server side (PHP) |
|---|---|---|
| Runs on | User's browser | Web server |
| Typical uses | Validation, effects, interactivity | Database access, authentication, page generation |
| Visibility | Source visible to user | Hidden from user |
| Speed | Immediate, no round trip | Needs a request to the server |
CSS (Cascading Style Sheets) is the language that describes how HTML elements should be displayed: their colours, fonts, sizes, spacing and layout. Separating style (CSS) from structure (HTML) keeps pages clean and lets one style sheet control a whole website. A CSS rule has a selector that picks the elements and a block of property: value declarations:
h1 {
color: navy;
font-family: Arial, sans-serif;
text-align: center;
}
CSS can be applied in three ways: inline using a style attribute on a single tag, internal using a <style> block in the page's <head>, and external using a separate .css file linked with <link rel="stylesheet" href="style.css">. The external style sheet is preferred because one file styles every page. The word "cascading" refers to the order of priority when several rules apply to the same element: inline styles win over internal, which win over external, and a more specific selector wins over a general one.