Lesson 2 · Websites from scratch
HTML that means something
Structure a profile page with semantic tags that browsers and screen readers understand.
About 20 minutes
Tab indents. Press Escape, then Tab, to leave the editor.
You could build an entire website out of <div> tags and make it look fine. It would also be a mess for screen readers, for search engines, for reader mode, and for you three weeks later. HTML's real job isn't how things look (that's CSS). It's saying what things are: this is the page's main heading, this is navigation, this is the main content, this is a footer. That's called semantic HTML, and it's what you'll use to build a profile page in this lesson.
Tags, elements and attributes, once
An element is a piece of the page, written with an opening tag, content and a closing tag. Attributes go inside the opening tag and add details.
<a href="#games">My games</a>
Here a is the element (a link), href="#games" is an attribute saying where it goes, and "My games" is the content. A few elements, like <img>, have no content and no closing tag.
Divs say nothing
A <div> is a generic box. It means "a group of stuff", nothing more. Look at this:
<div class="top">
<div class="big">Alex</div>
<div class="links"><a href="#about">About</a> <a href="#games">Games</a></div>
</div>
You can guess what's going on from the class names, but a browser can't. Class names are for you and your CSS; they carry no meaning to anything else. Now the semantic version:
<header>
<h1>Alex</h1>
<nav>
<a href="#about">About</a>
<a href="#games">Games</a>
</nav>
</header>
Same look once styled, but now a screen reader can announce "navigation" and let someone jump straight to it, a search engine knows "Alex" is the page's title, and reader mode knows what to keep.
The landmark tags
These are the tags that carve a page into regions. Screen readers list them as landmarks, so users can skip around the page the way you'd scan it with your eyes.
| Tag | What it is |
|---|---|
<header> | The intro area: site name, logo, often the nav |
<nav> | A block of major navigation links |
<main> | The main content. Use one per page |
<section> | A themed group of content, normally with its own heading |
<article> | Something that stands on its own: a post, a card, a comment |
<aside> | Side content related to the main content, like a fun-facts box |
<footer> | The closing area: credits, contact, copyright |
Headings are an outline
<h1> to <h6> aren't sizes, they're levels. Think of them as the outline of a school essay:
- One
<h1>: the page's title. <h2>for each main section.<h3>for parts inside anh2section, and so on.
Don't skip levels (an h2 followed by an h4) just because you like how the smaller one looks. Screen reader users often navigate by headings, and a skipped level makes it sound like a section is missing. If you want a different size, change it with CSS.
Pictures need words
Every <img> needs an alt attribute: a short description read aloud by screen readers and shown if the image fails to load. Describe what matters, not "image of".
<img src="avatar.png" alt="Alex holding a skateboard on a ramp">
If an image is pure decoration, use an empty alt="" so screen readers skip it. Emoji are text, so screen readers read their names out ("owl"). If an emoji stands in for a picture, you can give it a better label: <span role="img" aria-label="Pixel-art owl">🦉</span>.
Build it: your profile page
Challenge
Turn div soup into a real profile page
This page looks OK but it's all <div>s. Rebuild it with semantic tags, and make it yours:
- Wrap the name and links in a
<header>, make the name an<h1>, and put the links in a<nav>. - Put the sections in one
<main>, and make each section title an<h2>(use<section>for each part). - Turn the bottom line into a
<footer>. - Give the picture an
alt, or swap it for an emoji.
The CSS already styles the semantic tags, so the page should look better as you go.
- The page has a header with your name in an h1
- Your links are inside a nav (at least two)
- There's exactly one main
- Your sections are inside main and have h2 titles
- The page ends with a footer
- Headings go in order, with one h1 and no skipped levels
- Your picture has alt text, or you used an emoji instead
Recap
- Semantic HTML describes what content is; CSS decides how it looks.
- Landmarks (
header,nav,main,section,article,aside,footer) let screen reader users jump around the page. - Use one
h1, thenh2,h3… as an outline, without skipping levels. - Every
imgneedsalt: a real description, oralt=""for pure decoration. - Reach for a meaningful tag first; use
divwhen nothing else fits.
Finished this lesson?
Mark it complete to track your progress on this device.