Sub topic 3
Add your content: headings, text, lists, links and images
This chapter assumes you have the document skeleton and semantic landmarks (header, nav, main, section, footer) from the previous chapters. You will now fill the main element with real content. Each element you choose should describe what the content is, not how it looks. CSS handles the appearance later.
Headings give the page an outline
Headings run from h1 to h6. Browsers, search engines and screen readers use them to build an outline of the page. Screen reader users often jump from heading to heading to scan a page.
- Use one
h1per page. On this site it is your name. - Use
h2for each major section, such as Projects. - Use
h3for subsections inside anh2. - Do not skip levels, for example from
h2toh4, and do not pick a heading because its default size looks right. Fix the size with CSS.
Paragraphs, emphasis and lists
Wrap each block of prose in a p element. Use em for stress and strong for importance. Both carry meaning, unlike i and b, which only change the look.
Use a list when items belong together. A ul is an unordered list. An ol is an ordered list, where sequence matters. Each item goes in an li element, and a list may only contain li children directly.
Links and images
An a element creates a link, and its href attribute holds the destination.
- A link to another page of your own site can use a relative path, such as
resume.html. - A link to another site needs the full address, starting with
https://. - A link that opens the mail app uses
mailto:. - The link text should make sense on its own. "Read the case study" works. "Click here" does not.
An img element embeds a picture. It is a void element, so it has no closing tag. Give it these attributes:
srcis the path to the file.altdescribes the image for people who cannot see it. Use an emptyalt=""only for purely decorative images.widthandheightare the image's intrinsic size in pixels. The browser uses them to reserve space before the file loads, which prevents the page from jumping.
Worked example
Replace the contents of your main element with the following. It uses the section ids that the navigation links point to. The image path assumes you saved a file named desk.jpg in an images folder next to your HTML file.
<main>
<section id="about">
<h1>Jane Doe</h1>
<p>I build <strong>small, fast websites</strong> for local businesses.</p>
<img src="images/desk.jpg" width="800" height="600"
alt="Jane Doe working at a laptop on a wooden desk">
</section>
<section id="projects">
<h2>Projects</h2>
<h3>Skills I use</h3>
<ul>
<li>HTML and CSS</li>
<li>Accessibility testing</li>
<li>Performance tuning</li>
</ul>
<h3>How I start a project</h3>
<ol>
<li>Interview the client.</li>
<li>Sketch the page structure.</li>
<li>Build and test the page.</li>
</ol>
<p><a href="https://example.com/bakery-case-study">Read the bakery case study</a></p>
</section>
<section id="contact">
<h2>Contact</h2>
<p>Email me at <a href="mailto:[email protected]">[email protected]</a>.</p>
</section>
</main>Open the file in a browser. The page looks plain, with default fonts, bullets and a large image, and that is expected. The structure is correct, and the next chapters add the styling.
Common mistakes
| Mistake | Fix |
|---|---|
| Several `h1` elements on one page | Keep one `h1` and use `h2` for sections |
| Text placed directly inside a `ul` | Put each item in an `li` |
| Vague link text such as "here" | Describe the destination in the link text |
| Wrong image path, which shows a broken icon | Check the folder name, file name and capitalization |
Exercise
Your page has an h1, then an h3 for the Projects section because h3 looks the right size in the browser. What is wrong, and what should you do?
Show answer
The heading skips a level, so the page outline is broken for screen readers and search engines. Use an h2 for the Projects section, and adjust its size with CSS if the default look is not what you want.
Exercise
Why do you add width and height attributes to an img element, even though CSS can size it later?
Show answer
They tell the browser the image's proportions before the file loads. The browser can then reserve the right amount of space, so the content below does not jump when the image appears.