<h1> to <h6>
Headings, from the most important (h1) to the least (h6). Use one h1 per page.
<h1>Recipes</h1>
<h2>Breakfast</h2>
<h3>Pancakes</h3>Short entries with an example for each. When you need every detail, each entry links to the official documentation.
Headings, from the most important (h1) to the least (h6). Use one h1 per page.
<h1>Recipes</h1>
<h2>Breakfast</h2>
<h3>Pancakes</h3>A paragraph of text.
<p>Fresh bread every morning.</p>strong marks important words (bold); em adds spoken emphasis (italic).
<p>This is <strong>important</strong>, <em>really</em>.</p>A link. href says where it goes.
<a href="https://example.org">Visit</a>An image. Always add alt text that describes it.
<img src="cat.jpg" alt="A cat asleep on a chair">Bulleted and numbered lists. Each item is an li.
<ul>
<li>Milk</li>
<li>Eggs</li>
</ul>A table of data: rows (tr) made of header (th) and data (td) cells.
<table>
<tr><th>Day</th><th>Class</th></tr>
<tr><td>Mon</td><td>Maths</td></tr>
</table>Plain containers: div for blocks, span for words inside a line.
<div class="card">Tea <span class="price">$3</span></div>An input box and the label that names it. Match for and id.
<label for="name">Name</label>
<input id="name">A dropdown list of choices.
<select>
<option>Small</option>
<option>Large</option>
</select>A clickable button. Inside a form it submits the form.
<button>Save</button>Page regions that say what each part is for, which helps screen readers and search engines.
<header><h1>Shop</h1></header>
<nav><a href="#">Home</a></nav>
<main><p>Welcome!</p></main>
<footer><p>Open daily</p></footer>Page information in the head: the tab title, a search description and the phone viewport.
<head>
<title>Sunny Bakes</title>
<meta name="description" content="Fresh bread daily.">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>Sets the text color.
h1 { color: teal; }Set the size and typeface of text. Always end the font list with a generic family.
p { font-size: 20px; font-family: Georgia, serif; }A dot selects a class, a # selects an id.
.note { color: gray; }
#top { color: crimson; }Sets the background color or image of an element.
.hero { background: #fef3c7; padding: 20px; }Space inside an element's border.
.card { padding: 20px; background: #eef2ff; }Space outside an element's border.
.card { margin: 24px; background: #eef2ff; }Draw a line around a box and round its corners.
.card { border: 2px solid navy; border-radius: 12px; padding: 12px; }Lays out an element's children in a row (or a column).
.row { display: flex; gap: 12px; }Places children in rows and columns.
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }Space between the items in a flex or grid container.
.row { display: flex; gap: 24px; }Applies styles only when the screen matches a condition, such as a narrow width.
@media (max-width: 600px) {
body { background: lightyellow; }
}Matches an element while the mouse pointer is over it.
a:hover { color: crimson; }Animates a change in a property over time.
.btn { transition: transform 0.3s; }
.btn:hover { transform: scale(1.2); }Prints values to the console for checking your work.
console.log("Total:", 42);Declare variables. Use const when the value never changes.
const tax = 0.08;
let total = 0;
total = 100 + 100 * tax;
console.log(total);Defines reusable code that can take inputs and return a result.
function area(w, h) {
return w * h;
}
console.log(area(3, 4));Runs code only when a condition is true, with an optional fallback.
let age = 15;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Not yet");
}Ordered lists of values. Indexes start at 0.
const colors = ["red", "green"];
colors.push("blue");
console.log(colors.length, colors[0]);Loops over every item in an array.
for (const fruit of ["apple", "pear"]) {
console.log(fruit);
}Group related values under names (properties).
const pet = { name: "Milo", age: 3 };
pet.age = 4;
console.log(pet.name, pet.age);Strings in backticks that can include values with a dollar sign and braces.
const name = "Ada";
console.log(`Hi, ${name}!`);Finds the first element that matches a CSS selector.
const title = document.querySelector("h1");
title.textContent = "Found it!";Runs a function when something happens, like a click.
button.addEventListener("click", () => {
button.textContent = "Clicked!";
});Reads or replaces the text inside an element.
document.querySelector("#msg").textContent = "Saved";Make a new element, then add it to the page.
const li = document.createElement("li");
li.textContent = "New item";
list.append(li);Writes text and values to the console.
std::cout << "Score: " << score << std::endl;Every variable has a type: int, double, bool, std::string and more.
int age = 12;
double price = 4.99;
bool ready = true;
std::string name = "Ada";Runs code when a condition is true, and other code when it isn't.
if (marks >= 40) {
std::cout << "Pass";
} else {
std::cout << "Try again";
}Repeats a block a set number of times.
for (int i = 0; i < 3; i++) {
std::cout << i;
}Named, reusable code with a return type and parameters. Define them above main.
int square(int n) {
return n * n;
}A list that can grow. push_back adds; size counts.
std::vector<int> v = {1, 2};
v.push_back(3);
std::cout << v.size();A blueprint that bundles data and methods. Ends with };
class Dog {
public:
std::string name;
void bark() { std::cout << "Woof"; }
};Reads input typed by the user.
int age;
std::cin >> age;Prints a line of text to the console.
Console.WriteLine("Ready");Typed variables: int, double, bool, string and more.
int age = 12;
double price = 4.99;
bool ready = true;
string name = "Ada";Puts values inside text with $ and braces.
Console.WriteLine($"Total: {total}");Runs code only when a condition is true.
if (age >= 18)
{
Console.WriteLine("You can vote.");
}
else
{
Console.WriteLine("Not yet.");
}Repeat code a set number of times, or while a condition is true.
for (int i = 1; i <= 3; i++)
{
Console.WriteLine(i);
}Named, reusable code inside a class.
static int Square(int n)
{
return n * n;
}A list that can grow; foreach visits every item.
List<string> names = new List<string>();
names.Add("Asha");
foreach (string n in names)
{
Console.WriteLine(n);
}A class is a blueprint; new creates an object from it.
class Dog
{
public string Name;
}
Dog rex = new Dog();
rex.Name = "Rex";Reads a line of text typed by the user.
string name = Console.ReadLine();No entries match. Try a shorter word.