Learn HTML and CSS: Headings and paragraphs
Headings and paragraphs
Maggie has typed out the chalkboard: one long wall of text. "Could it look a bit tidier? Even I get lost in my flavours."
Six levels of headings
HTML has six levels of headings: <h1> to <h6>. <h1> is the title of the whole page, <h2> a chapter, <h3> a section of that chapter, and so on.
Choose a heading for what it means, not for how big it is: you set the size later with CSS. Search engines and screen readers use the headings as a table of contents.
So: one <h1> per page, and never skip a level. Under an <h2> comes an <h3>, not an <h4>.
<main> <h1>Cold Comfort</h1> <h2>Our flavours</h2> <h3>Fruity</h3> <p>Strawberry, lemon and mango.</p> <h3>Creamy</h3> <p>Vanilla, pistachio and honeycomb.</p> <h2>Opening hours</h2> <p>Every day from 1 pm to 10 pm.</p></main>Paragraphs and white space
Ordinary text goes in a paragraph: <p>. Each <p> starts on a new line, with some space above and below.
Careful: the browser ignores how you type your code. Line breaks and extra spaces all become one space. Look at the first paragraph below: in the code it's on two lines, on the page it's on one.
So if you want a new paragraph, you need a new <p>.
<main> <h2>About us</h2> <p>Maggie has been making ice cream on the seafront for twenty summers.</p> <p>Fresh every morning, with milk from a farm on the Downs.</p></main>Try it yourself
Maggie typed the text without tags. Make Opening hours and Ice cream cakes chapters, and the two sentences below them paragraphs.
<main> <h1>Cold Comfort</h1> Opening hours Every day from 1 pm to 10 pm, Sundays too. Ice cream cakes Order your cake two days in advance.</main>body { margin: 0; font-family: system-ui, sans-serif; background: #fff8f0; color: #3b2a1a;}header { padding: 24px 16px; background: #ffd6e0;}.logo { display: inline-block; margin: 8px 0 0; padding: 6px 18px; border-radius: 999px; background: #ffffff; font-size: 28px;}.slogan { margin: 8px 0 0;}main { padding: 8px 16px 24px;}Ready for more?
The full lesson has 6 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson