The Web
HTML & CSS Essentials
Build and style a web page: HTML document structure, common elements, links, images, lists, tables and forms, then CSS selectors, the box model, colours, fonts and Flexbox — with a live editor.
Every web page is built from three languages:
| Language | Role | Analogy |
|---|---|---|
| HTML | structure and content | the skeleton |
| CSS | presentation and layout | the clothes |
| JavaScript | behaviour and interaction | the muscles |
HTML: structure
HTML marks up content with elements, written as tags: <p>A paragraph</p>. Tags can have attributes: <a href="https://example.com">a link</a>.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My first page</title>
</head>
<body>
<h1>Hello, I'm Asha</h1>
<p>I study <strong>computer science</strong> at Kalvium.</p>
<a href="https://github.com">My GitHub</a>
</body>
</html><head>holds information about the page (title, character set, CSS links).<body>holds what is shown.
Common elements
| Element | Purpose |
|---|---|
<h1> … <h6> |
headings, from most to least important |
<p> |
paragraph |
<a href="…"> |
link |
<img src="…" alt="…"> |
image (the alt text is read by screen readers) |
<ul>, <ol>, <li> |
bulleted list, numbered list, list item |
<table>, <tr>, <th>, <td> |
table, row, header cell, data cell |
<form>, <input>, <button>, <label> |
forms |
<div>, <span> |
generic block and inline containers |
<header>, <nav>, <main>, <section>, <footer> |
semantic layout regions |
Semantic elements tell browsers, search engines and screen readers what each part means — prefer them to plain <div>s.
CSS: style
CSS rules have a selector and declarations:
h1 {
color: #2e8b47;
font-size: 2rem;
}
.card { /* class selector: <div class="card"> */
padding: 16px;
border-radius: 12px;
}
#signup { } /* id selector: <form id="signup"> */
nav a:hover { } /* descendant + state */| Selector | Matches |
|---|---|
p |
every <p> |
.card |
elements with class="card" |
#main |
the element with id="main" |
nav a |
<a> elements inside <nav> |
a:hover |
links under the mouse pointer |
When rules conflict, the more specific selector wins (id > class > element), and later rules beat earlier ones of equal specificity — the cascade.
The box model
Every element is a box: content, surrounded by padding, then a border, then margin (space outside).
.box {
width: 200px;
padding: 16px; /* inside the border */
border: 2px solid #333;
margin: 24px auto; /* outside; auto centres horizontally */
box-sizing: border-box; /* width now includes padding and border */
}Flexbox layout
Flexbox arranges children in a row or column with easy alignment and spacing:
.row {
display: flex;
gap: 12px;
justify-content: space-between; /* along the main axis */
align-items: center; /* across it */
flex-wrap: wrap;
}Try it: a live editor
Edit the HTML and CSS — the preview updates as you type:
Responsive design
Phones, tablets and laptops need different layouts. Two essentials:
<meta name="viewport" content="width=device-width, initial-scale=1">@media (max-width: 600px) {
.row { flex-direction: column; } /* stack on small screens */
}Test yourself
4 questions · pick an answer to check it instantly
- 1
Which element creates a link?
<a href="…">is the anchor element;<link>connects stylesheets in the head. - 2
Which CSS selector matches
<div class="card">?A dot selects by class; a hash selects by id. - 3
In the box model, which property adds space inside the border?
Padding sits between the content and the border; margin is outside the border. - 4
Why should
<img>have analtattribute?Alt text makes images accessible.