HTML Tutorial / Accessibility Basics: Headings, Links, Images, and Keyboard
Accessible HTML starts with choosing elements for their meaning. Use headings in a logical order, write links that reveal their destination, give images appropriate alternatives, and make sure people can complete interactions with a keyboard.
Use headings to describe hierarchy
A heading is not merely large text. It marks a level in the document: a page topic may use h1, major sections h2, and their subsections h3. Do not jump to h4 because you like its default size; adjust appearance with CSS. Someone reading only the headings should be able to understand the page's outline. Compare heading levels and paragraphs in the examples from Headings and Paragraphs.
For example, “Delivery information” can be a main section, with “Delivery areas” and “Delivery times” as subsections. Avoid empty headings or headings that do not match the text below. The heading hierarchy helps people scan visually and navigate with assistive technology.
Make links and images understandable
A list of links all named “here” gives little clue about their destinations. Write the purpose in the link text, as in <a href="guide.html">Read the user guide</a>. If the link downloads a file, make its type clear in the surrounding context. Review role-appropriate image alternatives and dimensions in Images: img, Alt Text, and Dimensions.
An informative image's alt text should convey the information it contributes here. A purely decorative image that repeats nearby text may use alt="". An image used as a link must also convey the link's purpose, such as “Open the user guide.” Avoid listing every visible color or shape when the function is what matters. The W3C WAI image decision tree helps decide which alternative is appropriate.
Try the page without a mouse
- Use
Tabto move through links, form fields, and buttons. - Check that the focused element is visibly identifiable.
- Activate controls using
EnterorSpaceas appropriate. - If a form reports an error, read it, return to the field, correct the value, and submit again.
A div with only a click handler does not automatically gain a button's meaning or keyboard behavior. Use a for navigation and button for actions. If a menu or disclosure opens and closes, check where keyboard focus moves afterward. Focus should not disappear into hidden content, and the navigation order should roughly match the reading order. Check the explicit association of field names with the label-click exercise in Connect Labels and Inputs Correctly.
Typically, a focused link opens with Enter, while a button activates with Enter or Space. Choosing an element that matches navigation or action gives keyboard users the behavior they expect, rather than forcing a link to imitate a button or vice versa.
A small page for manual testing
Save the complete code as accessible-page.html and place the 960px example image from the image lesson beside it. The form is for validation and GET-value inspection, not a message-receiving service.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Keyboard-testing practice</title>
<style>
body { margin: 1rem; font-family: sans-serif; line-height: 1.6; }
img { max-width: 100%; height: auto; }
input { max-width: 100%; font: inherit; }
:focus-visible { outline: 3px solid #005fcc; outline-offset: 3px; }
</style>
</head>
<body>
<a href="#main-content">Skip to main content</a>
<header>
<nav aria-label="On this page">
<a href="#guide">Visitor guide</a>
<a href="#contact">Contact practice</a>
</nav>
</header>
<main id="main-content" tabindex="-1">
<h1>Small Garden guide</h1>
<section id="guide">
<h2>Visitor guide</h2>
<p>Bring comfortable shoes and water.</p>
<img src="html-image-sample-lake-tree-960-v1.webp"
alt="A tree on a small island in a lake with mountains beyond" width="960" height="540">
</section>
<section id="contact">
<h2>Practice a contact field</h2>
<form method="get">
<label for="practice-email">Email (required)</label>
<input id="practice-email" name="email" type="email"
aria-describedby="email-help" required>
<p id="email-help">Use name@example.com instead of a real address.</p>
<button type="submit">Inspect entered values</button>
</form>
</section>
</main>
</body>
</html>
- Press Tab once to focus the skip link, then Enter to bypass the repeated menu and reach the main content.
- The main element's tabindex="-1" lets it receive focus without adding another normal Tab stop. Check that subsequent Tab movement follows a useful reading order.
- Reach the form and compare an empty submission, an invalid value such as abc, and a correctly formatted test address. Its label and instructions should remain available as you type.
- Check the text, image, and field at 390px and with zoom. Temporarily rename the image to review its alternative text, then restore the filename.
| Check | Problematic approach | Approach in this example |
|---|---|---|
| Navigation | A div with only a click handler | A link with a real href |
| Field name | Only a disappearing placeholder | A label and persistent instructions |
| Focus | Removing outlines without a replacement | A visible CSS focus indicator |
HTML supplies semantics and native interactions; CSS supplies layout and the visual focus treatment. Custom errors or complex menus may need additional JavaScript state and focus handling. Passing this exercise is not a claim that the page satisfies every accessibility requirement.
W3C WAI page-structure tutorial
Understand what testing can and cannot prove
An automated checker can find some markup errors, but it cannot always judge whether a link is understandable or an image description is useful in context. Combine tool results with keyboard testing, zooming, and, when appropriate, a screen reader. Start with the site's important user journeys rather than treating a zero-error report as a guarantee. The MDN guide to HTML accessibility covers more native HTML patterns.




