Headings, paragraphs and pictures
Headings go from h1, the largest and most important, down to h6, the smallest. A paragraph is the p tag. To centre or right-align a paragraph, put the rule in a style attribute: <p style="text-align:center">. An image uses the img tag with two attributes: src, the path of the picture file, and alt, a short text that describes the picture for visitors who cannot see it or when the file does not load. Always write alt. The img tag stands alone, so it has no closing tag. Be careful with nesting: close a paragraph before you open a heading. A browser will close an open paragraph for you when a heading begins, but do not rely on that: write the closing tag yourself, so the code is clear and the same everywhere. Older pages used the tag <p align="center"> and capital letters; today we write valid, lowercase code.
| Tag | Job |
|---|---|
| h1 … h6 | headings: h1 largest, h6 smallest |
| p | paragraph |
| img (src, alt) | picture from a file, with a description |
| br | line break, no closing tag |
1<h1>Illustrated Dictionary</h1> 2<p style="text-align:center">Welcome to the club dictionary.</p> 3<img src="pic/router.webp" alt="A router with four cables" width="200"> 4<h2>Latest term</h2> 5<p style="text-align:right">Router</p>
From top to bottom: a large heading, a centred line of text, the picture (200 wide), a smaller heading, and a word on the right-hand side.
| Older habit | Valid way |
|---|---|
| <p align="center"> | <p style="text-align:center"> |
| <img src="pic/a.webp"> | <img src="pic/a.webp" alt="description"> |
| <p>Intro<h1>Title</h1> | <p>Intro</p><h1>Title</h1> |
| <H1>…</H1> | <h1>…</h1> |
On paper write the body of a page about your favourite animal: a main heading, a centred paragraph, a picture (src and alt) and a smaller heading with a right-aligned paragraph under it. Check that each paragraph is closed and each tag is lowercase.