DevNotes
@devnotes ·
HTML Part 2: Headings, text and lists
Most of a web page is text, and a handful of tags give it its shape.
Headings
HTML has six levels of heading, <h1> to <h6>. They work like the headings in a textbook:
Use one <h1> per page, for its main title. Sections get <h2>, and parts inside a section get <h3>. Don't skip levels, and don't pick a heading for its size. Size is something CSS decides.
This matters more than it looks. People using screen readers often move through a page by jumping from heading to heading, and search engines read headings to work out what a page is about.
Paragraphs and spaces
Each paragraph goes in its own <p>. The browser doesn't keep the spacing of your code, though: every run of spaces and line breaks turns into a single space.
So pressing Enter in your code doesn't start a new line on the page. For a new paragraph, use a new <p>. For a line break inside one, like in an address or a poem, use <br>:
Don't stack <br> tags to make gaps between things. Spacing is CSS's job too.
Bold and italic, with meaning
<strong> marks something important, and <em> marks stress: the word you'd lean on if you said the sentence out loud. Browsers show them as bold and italic.
There's also <b> and <i>. They make text bold or italic without calling it important, which suits things like a product name or a word from another language. When you mean "this matters", use <strong>.
Lists
Use <ul> when the order doesn't matter and <ol> when it does. Each item goes in an <li>.
For a list inside a list, put the inner list inside an <li>, never straight inside the <ul>.
Comments
Comments are notes to yourself, and the browser skips them. Anyone can still read them with View Source, though, so never leave a password in one.
A common mistake
Close tags in the reverse order you opened them, like boxes inside boxes:
- Wrong:
<p><strong>Hello</p></strong> - Right:
<p><strong>Hello</strong></p>
Try it
Make a page about your favourite dish: an <h1> with its name, an <h2> for the ingredients with a <ul>, and an <h2> for the steps with an <ol>.
Next: HTML Part 3: Links and images
Join WIK to like and reply to DevNotes and see more like this.