Privacy note: We capture your IP address to provide customised and focused services. See our Privacy Policy.

Full-Stack Web Development — Alpha School

Lesson 18: Testing, Debugging and Making Sites Accessible

A website is finished not when it works on your computer, but when it works for your visitors, including the ones using a keyboard, a screen reader, a small phone or a slow connection. Testing is the habit of checking that, and debugging is the skill of finding out why something does not work and fixing it. This lesson covers a practical testing checklist you can run on any page, the debugging tools in your browser, and the accessibility habits that make your site usable by everyone, which is not an optional extra: in many countries it is a legal requirement for public services, and everywhere it is simply good design, because the features that help a blind visitor also help a visitor on a phone in bright sunlight.

A testing checklist for every page

Run through this checklist before you call any page finished. First, open it in a second browser and on a phone, and check the layout, the images and the links. Second, use the keyboard only, pressing Tab to move through the page: every link and button should be reachable, the focus should always be visible, and the order should follow the visual order. Third, zoom to 200 percent and confirm nothing overlaps and no text is cut off. Fourth, turn off JavaScript in the browser settings and check the page still makes sense, because the content should work even if the scripts fail. Fifth, check every form by submitting it empty, with mistakes, and correctly, and read the error messages. Sixth, run the page through the free W3C validator and fix the errors it reports. The whole list takes about ten minutes, and it catches most problems before your visitors do.

Debugging with the browser tools

When something goes wrong, the browser's developer tools are your laboratory. The Console tab shows JavaScript errors with the file and line number, and you can type expressions there to inspect values, such as document.querySelector('h1'), to check what your code actually found. The Elements tab shows the live HTML and CSS, and you can change a style there to test a fix before editing your file. The Network tab shows every request the page made, its status code, and how long it took, which tells you whether a missing image or a failed API call is the problem. The most reliable debugging method is to narrow the problem down: comment out half the code, test, and repeat until the fault is in a small piece you can read properly, which beats staring at a whole file hoping the bug will announce itself.

Accessibility habits that help everyone

Accessibility rests on a few habits you already know, plus a few new ones. Use real buttons for actions and real links for navigation, because a div styled to look like a button cannot be reached by a keyboard and is not announced as a button by a screen reader. Give every form field a label, every image an alt text, and every page a single h1 and a sensible heading order. Make sure text contrasts enough with its background: a contrast ratio of at least 4.5 to 1 for normal text is the standard, and there are free checkers that will test any colour pair. Do not rely on colour alone to mean something, because a visitor who cannot tell red from green will miss it, so pair colour with words or icons. Finally, respect reduced motion: some visitors ask their device to reduce animations, and your CSS should honour that with a media query that turns movement off for them.

/* Respect visitors who ask for reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none;
    transition: none;
    scroll-behavior: auto;
  }
}

Fixing what you find

Testing is only useful if you act on what it finds, so keep a simple list: the problem, where it happens, and what you will change. Fix the most serious problems first, the ones that stop someone using the page at all, such as a button that cannot be reached by keyboard, and then the ones that confuse, such as a vague error message. After each fix, test again, because a fix in one place can break something in another, and a page that passed yesterday can fail today after a careless edit. That loop, test, fix, test again, is the rhythm of professional development, and it is also the habit that will make your capstone genuinely good rather than merely finished. Keep the list, work through it honestly, and be proud of a page that works for everyone.

Key Terms

Testing
Checking that a page works as intended, for different visitors, devices and inputs.
Debugging
Finding out why something does not work and fixing it, using tools and a methodical approach.
Keyboard navigation
Using a page with Tab and Enter instead of a mouse; every control must be reachable this way.
Focus
The visible outline showing which element the keyboard is currently on.
Contrast ratio
A measure of how different text is from its background; at least 4.5 to 1 is the standard for normal text.
prefers-reduced-motion
A setting visitors can use to ask for less animation, which your CSS should honour.
Validator
A tool, such as the W3C validator, that reads your code and lists errors.

Discussion Questions

  1. Why is testing with a keyboard only one of the most valuable checks you can run?
  2. A button looks perfect with a mouse but cannot be reached by keyboard. How serious is that, and why?
  3. Why should you test a page again after every fix, rather than assuming the fix worked?

Practice Questions

  1. Name three things to check on every page before calling it finished.
  2. Which browser tab shows JavaScript errors with file and line numbers?
  3. What does a contrast ratio of 4.5 to 1 mean?
  4. Why should an action use a real <button> instead of a styled <div>?
  5. What should your CSS do when a visitor asks for reduced motion?
Show answers
  1. Any three from the checklist, such as keyboard navigation, 200 percent zoom, and testing in a second browser. Each one catches problems a quick look on your own computer would miss.
  2. The Console tab of the developer tools. It also lets you type expressions to inspect values while the page is running.
  3. It is the minimum contrast between normal text and its background. Text below that standard is hard to read for many visitors, including those with low vision.
  4. A real button can be reached by keyboard and is announced as a button by screen readers. A div is not, however it looks.
  5. Turn animations and transitions off for them. A media query for prefers-reduced-motion: reduce can set animation and transition to none.
Keep reading to complete this lesson