Page Structure and Elements
An HTML page is made of elements. Most elements have an opening tag, some content and a closing tag. The closing tag has a forward slash.
A tag is the label in angle brackets, like <p>. An element is the whole thing: opening tag, content and closing tag together. The closing tag tells the browser where the element ends - without it, the browser has to guess, and it may guess wrong.
<p>This is a paragraph.</p>Elements can sit inside other elements. This is called nesting. Always close the inner element before the outer one.
Nesting is like boxes inside boxes: a list box holds item boxes, a section holds headings and paragraphs. The rule "close the inner one first" keeps the boxes neat. <p><b>Hi</b></p> is right; <p><b>Hi</p></b> is tangled. Indenting inner elements with spaces makes the structure easy to see.
The main parts of a page
<!DOCTYPE html>tells the browser this is a modern HTML page.<html>wraps the whole page.<head>holds information about the page, such as its title.<body>holds everything the visitor sees.
Every HTML page you'll ever write starts with this same skeleton. Most code editors (like VS Code) can create it for you: type ! and press Tab. Learn what each part means once, and you'll recognise it everywhere.
<!DOCTYPE html>
<html>
<head>
<title>Nesting example</title>
</head>
<body>
<p>This sentence has a <b>bold</b> word and an <i>italic</i> word.</p>
<p>Line one<br>Line two after a line break.</p>
</body>
</html>▶ Try it yourself<br> for a line break, are empty: they have no content and no closing tag.- Elements = opening tag + content + closing tag.
- Elements nest inside each other; close the inner one first.
- Every page:
<!DOCTYPE html>,<html>,<head>,<body>. - Empty elements like
<br>and<img>have no closing tag.
