Vocabulary for this course

The terms the chapters assume, in plain words. You can open this from any chapter.

accessible name
What a browser tells a screen reader an element is called, taken from its text, its label, or an alternative description.
aria-label
An attribute that gives a control an accessible name when no visible text can serve as one.
attribute
A name, sometimes with a value, inside an opening tag that describes the element further, such as where a link goes.
control
An interactive part of a page, such as a text box, checkbox, or button, that a person can operate.
element
One complete piece of a page: an opening tag, its content, and a closing tag, or a single tag when it holds nothing.
empty element
A tag that holds nothing and has no closing partner, such as an image or a line break.
for attribute
An attribute on a label that names the control it describes, so clicking the text operates that control.
form action
The address a submitted form sends its values to, declared in the opening tag of the form.
id attribute
An attribute that gives one element a unique name, which a link or a label can point to.
label
The text attached to a control that says what it is for; clicking it focuses or operates the control it belongs to.
landmark
A page region with a recognised purpose, such as header, nav, or main, that a screen reader can jump to directly.
markup
The tags and attributes that describe the structure of a document, as opposed to its styling or behaviour.
method
The attribute that says whether a form's values travel in the address or in the request body.
name attribute
An attribute that gives a form control a key for its value when the form is submitted.
regular expression
A pattern of characters used to test or match text, such as the shape an email address must have.
request body
The part of a form submission that carries the field values, separate from the address.
reset button
A button that puts every control in a form back to the value it had when the page loaded.
sandbox
An isolated place where a page runs without reaching the rest of the site or the network.
screen reader
Software that speaks a page aloud or shows it in braille, so someone who cannot see the display can still use it.
tag
The name of an element written in angle brackets, such as p or img, which marks where that piece of the page begins or ends.

HTML from the ground up

Text, links and images

The three things almost every page is made of: headings and paragraphs that carry meaning, links that go somewhere, and images that everyone can understand.

Part 2 of 13

Beginner15 min readBack to Courses

Headings carry the outline

There are six heading levels, <h1> to <h6>, and they are an outline, not a font size. A page has one <h1> — what this page is about — and <h2> for its main sections. Skipping from <h1> to <h3> does not look wrong; it reads wrong, because a screen reader announces the level and a crawler builds a table of contents from it.

Paragraphs are <p>. Emphasis is <em> for stress and <strong> for importance — both change meaning, and both are announced. If you only want bold text with no meaning attached, that is a styling job, not a markup one.

Which element, when

  • <h2> — a section of the page, under the <h1>.
  • <p> — a paragraph of prose.
  • <strong> — this word matters: a warning, a required field, the key noun.
  • <em> — stress on a word, the way you would lean on it while speaking.
  • <br> — a line break inside a paragraph, for an address or a poem. Never to space paragraphs apart; writing the paragraphs as paragraphs is markup’s job, and the space between them is not markup’s at all.

An article with an outline

Add a second `<h2>` section with a paragraph under it, and mark one word as important with `<strong>`.

Live Preview
Console output will appear here...

2 left to do

  • There are at least two h2 sections
  • One word is marked as important with the strong element

The new section goes after the first one, inside <body>.

Links

A link is an <a> with an href. The destination is a URL: absolute (https://example.com/pricing) for another site, relative (./about.html, /pricing) for somewhere on yours, or a fragment (#pricing) for somewhere on this page.

The text of the link is what a person clicks and what a search engine reads, so it should describe the destination. "Read the pricing page" survives being read out of context; "click here" does not, and screen reader users often jump from link to link.

Links that say where they go

Add a second link that points at a page on the same site, and give both links text that describes the destination rather than "click here".

Live Preview
Console output will appear here...

1 left to do

  • There are at least two links

A relative link looks like <a href="./about.html">About this site</a>.

Links within the page

An id gives an element a name a fragment link can reach. <h2 id="pricing">Pricing</h2> together with <a href="#pricing">See the pricing</a> moves the reader down the page without a reload, and the browser updates the address so the position can be shared.

The id must be unique on the page. A fragment goes to the first match, so a duplicate sends every link to the same place. An absolute URL points elsewhere; a relative path survives a move to another domain.

How a relative path resolves

A relative path is resolved against the address of the page, not against your folder on disk. From https://example.com/recipes/bread.html, a link to ./about.html means https://example.com/recipes/about.html; /pricing starts again at the domain root; and ../index.html climbs one directory before looking. A trailing slash says the address is a directory, so recipes/ asks the server for that folder’s index file rather than a file called recipes. That is why a link can work on your machine and break after upload: the page moved, and a path written from the old place no longer resolves.

Images

An image is <img src="…" alt="…">. The alt text is not a caption and not a keyword field: it is what replaces the image when it cannot be seen — a broken file, a slow connection, or a screen reader. Describe what the image does in the page. A decorative image gets alt="", which tells assistive technology to skip it.

Giving width and height lets the browser reserve space before the image arrives, so the text does not jump around as it loads. Below, the images are inline data URLs so the example runs without a single network request — a real project would point src at a file.

Images with meaning

Give both images an alt that describes them (or an empty alt if they are decorative), and add a caption to the figure.

Live Preview
Console output will appear here...

2 left to do

  • The image has an alt attribute (empty is fine when decorative)
  • The figure has a caption

<figcaption> sits inside <figure>, after the <img>.

Whitespace is not markup

In the source, a run of spaces, tabs and newlines collapses to a single space when the page is drawn, so you can indent HTML without changing the words. A line break inside a paragraph is <br>; a space that must not collapse is &nbsp;, a last resort because it stops the line wrapping there.

Characters with a meaning in markup are written as references: &lt; for a literal less-than sign, &amp; for an ampersand, and &quot; inside a quoted attribute. The browser decodes them before the text reaches the reader, so the page says what you meant instead of starting a tag in the middle of a sentence. A reference is also how you write a character that is awkward to type, such as &copy; for the copyright sign.

Never write the words "image of" or "picture of" in alt. The reader already knows it is an image — it is announced as one. Describe the content instead.

Three quiet link and image mistakes: an href of # that looks like a link but goes nowhere; an image with no alt at all, so a screen reader reads the file name; and a relative path that only works from one directory. Check where each link really goes, and describe each image by what it adds to the page.

Try these next

  • Link to a section of the same page with #id, then reload with the fragment still attached to the address.
  • Write a sentence containing < and & with character references, and check the rendered text.
  • Add a purely decorative image with alt="" and compare what a screen reader skips.

Check what you learned

One question at a time. A wrong answer explains itself — take another go.

Part 1 of 5

What is alt text for?