Sub topic 3
Add your content: headings, text, lists, links and images
This chapter fills the page skeleton with real content. It assumes you can edit and save files, open an HTML file in a browser, and that you already have the document skeleton and landmark elements (header, nav, main, footer) from the previous chapters. Here you choose the right element for each piece of content, and you learn the mistakes that cause trouble later in CSS, accessibility and layout.
Why element choice matters
Browsers, screen readers and search engines read the element names, not the way the text looks. A paragraph that is bold and large is still a paragraph. A real heading is a heading, and assistive technology lets people jump between headings. You can change how anything looks with CSS later. You cannot easily fix the wrong meaning.
The rule for this chapter: pick the element for what the content is, then style it.
Headings
HTML has six heading levels, h1 to h6. They form an outline of the page.
- Use one
h1for the page's main subject. On this site it is your name. - Use
h2for each major section (Projects, Contact). - Use
h3inside anh2section when it has sub-parts, such as one heading per project. - Do not skip levels to get a smaller font. Going from
h2toh4leaves a gap in the outline. Change the size in CSS.
<section id="projects">
<h2>Projects</h2>
<article>
<h3>Recipe Finder</h3>
<p>A small search page for cooking ideas.</p>
</article>
<article>
<h3>Trail Notes</h3>
<p>A hiking log that works offline.</p>
</article>
</section>Here each project is an article because it makes sense on its own. A section groups related content under a heading. If you are unsure, use section for chapters of the page and article for self-contained items.
Text: paragraphs and inline elements
Every block of prose goes in a p element. Do not use blank lines or <br> to create space between paragraphs. Browsers collapse extra whitespace in HTML, and spacing is a CSS job (you will use margins for it).
Inside a paragraph, use inline elements to add meaning.
| Element | Meaning | Default look |
|---|---|---|
| `strong` | Strong importance | Bold |
| `em` | Stress emphasis, as in spoken tone | Italic |
| `code` | A short piece of code | Monospace |
| `time` | A date or time that a machine can read | Plain |
| `abbr` | An abbreviation, with the full form in `title` | Dotted underline in some browsers |
Avoid b and i for emphasis. They only mean "draw attention" and "alternate voice", and they carry no importance. Use them rarely.
<p>
I am a <strong>front-end developer</strong> who cares about
<em>fast</em> pages. I started in
<time datetime="2021-03">March 2021</time> and mostly write
<code>HTML</code> and <code>CSS</code>.
</p>The datetime value is in a standard machine format (YYYY-MM-DD, or YYYY-MM for a month). The visible text can be anything readable.
Special characters
The characters <, > and & have meaning in HTML. To show them as text, write <, > and &. The footer in the skeleton uses © for the © sign. If your file is saved as UTF-8 (the <meta charset="utf-8"> line expects this), you can also type most characters directly, such as é or —.
Lists
HTML has three kinds of lists. Choose by meaning.
ul(unordered list) is for items where order does not matter.ol(ordered list) is for steps or rankings, where order matters.dl(description list) pairs terms with descriptions, such as a skill and what you did with it.
Only li elements may be direct children of ul and ol. Put text inside the li, not between items.
<h3>Skills</h3>
<ul>
<li>Semantic HTML</li>
<li>Responsive CSS</li>
<li>Accessibility checks</li>
</ul>
<h3>How I work</h3>
<ol>
<li>Sketch the page on paper.</li>
<li>Write the HTML.</li>
<li>Add the CSS.</li>
</ol>
<h3>Tools</h3>
<dl>
<dt>Editor</dt>
<dd>Visual Studio Code</dd>
<dt>Browser</dt>
<dd>Firefox with developer tools</dd>
</dl>Lists can nest. Place the inner ul or ol inside an li, never directly inside the outer list.
The navigation in the skeleton is also a list. A menu is a group of related links, so ul fits, and screen readers announce how many items it has. In the Flexbox chapter you will remove the bullets with CSS and lay the list out in a row.
Links
The a (anchor) element makes a link. Its href attribute holds the destination. The kind of destination changes how you write it.
| Destination | Example `href` | Notes |
|---|---|---|
| Section on this page | `#about` | Matches an `id` on the same page |
| Another file on your site | `projects/trail.html` | A relative path |
| Another site | `https://example.com/` | A full URL |
| Email address | `mailto:[email protected]` | Opens the mail app |
Relative paths
A relative path starts from the folder of the current file.
photo.jpgis in the same folder.images/photo.jpgis in a subfolder namedimages.../photo.jpgis one folder up.
Most broken images and stylesheets on a new site come from a wrong relative path or a different letter case. Many web servers treat Photo.jpg and photo.jpg as different files, even though your own computer may not. Use lowercase file names with hyphens and no spaces.
Link text
Link text must make sense out of context, because screen reader users often list all links on a page.
<!-- Weak -->
<p>To read my résumé, <a href="resume.pdf">click here</a>.</p>
<!-- Better -->
<p>Read my <a href="resume.pdf">résumé (PDF, 120 KB)</a>.</p>Opening links in a new tab
You can add target="_blank" to open a link in a new tab. Do it only when leaving the page would lose the reader's work, and tell the reader. Modern browsers already treat target="_blank" links as if rel="noopener" were set, but adding it is harmless and protects older browsers.
<a href="https://developer.mozilla.org/" target="_blank" rel="noopener">
MDN Web Docs (opens in a new tab)
</a>Images
The img element is a void element: it has no closing tag and no content. Four attributes matter most.
srcis the file path.altis the text alternative, used by screen readers and shown if the image fails to load.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.loading="lazy"delays loading of images below the first screen.
<img
src="images/jane-desk.jpg"
width="800"
height="800"
alt="Portrait of Jane Doe at her desk">A later chapter covers srcset and sizes, which let the browser choose among several file sizes. The basic attributes above still apply.
Writing useful alt text
Describe the purpose of the image in context, not every pixel.
- A photo that adds information: describe what matters. "Portrait of Jane Doe at her desk" is enough.
- An image that is a link: describe where the link goes, such as
alt="Jane Doe's home page". - A purely decorative image: use an empty
alt="", so screen readers skip it. Never leave the attribute out, because then some screen readers read the file name aloud. - Do not start with "Image of" or "Picture of". The reader already knows it is an image.
Figures and captions
When an image has a visible caption, wrap both in figure and figcaption.
<figure>
<img
src="images/trail-notes.png"
width="1200"
height="750"
alt="Trail Notes app showing a list of three hikes">
<figcaption>The Trail Notes home screen on a phone.</figcaption>
</figure>Putting it together
The next code block fills in the about and projects sections from the skeleton. Save it inside <main> and put a photo named jane-desk.jpg in an images folder, or the image will show its alt text instead.
<section id="about">
<h1>Jane Doe</h1>
<p>I build <strong>small, fast websites</strong> for local businesses.</p>
<img
src="images/jane-desk.jpg"
width="800"
height="800"
alt="Portrait of Jane Doe at her desk">
<h2>Skills</h2>
<ul>
<li>Semantic HTML</li>
<li>Responsive CSS</li>
</ul>
</section>
<section id="projects">
<h2>Projects</h2>
<article>
<h3>Trail Notes</h3>
<p>
A hiking log that works offline.
<a href="https://example.com/trail-notes">View Trail Notes</a>
</p>
</article>
</section>Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Image shows a broken icon | Wrong path or letter case | Check the folder and the exact file name |
| Link to a section does nothing | `href="#about"` but the id is `About` or missing | Make the id match exactly, including case |
| Extra space does not appear in text | HTML collapses whitespace | Use separate `p` elements and CSS margins |
| Text after a list sits inside the list | Missing closing `</li>` or `</ul>` | Close each tag and indent to check nesting |
| Headings look wrong in the outline | Levels chosen for size | Pick levels for structure, resize with CSS |
Exercise
A teammate writes <h4>Contact</h4> directly after an <h2>Projects</h2> section because they like the smaller text. What is wrong, and how should it be fixed?
Show answer
The jump from h2 to h4 skips a level, so the outline has a gap and screen reader users who navigate by headings get a misleading structure. Use <h2>Contact</h2> because Contact is a major section, and make the text smaller with a CSS rule such as h2 { font-size: 1.25rem; } or a more specific selector.
Exercise
You add a decorative divider image that carries no information. What should its alt attribute be, and why not omit it?
Show answer
Use an empty value, alt="". Screen readers then skip the image. If the attribute is missing, some screen readers read out the file name, which is noise.
Exercise
Your page is in index.html. A photo is at images/jane-desk.jpg, and a second page at projects/trail.html needs to show it. What src should the second page use?
Show answer
../images/jane-desk.jpg. The path starts from the projects folder, .. goes up one folder to the site root, and then it enters images.