On this page9 sections
Lecture 032: Debugging & Validating HTML
| Category | 5: Code, Characters & Standards |
| Lecture | 032 of 048 |
| Estimated video length | 8 min |
| Target | HTML5 · any modern browser |
| Level | Beginner |
HTML rarely shows an error message. The browser silently "fixes" mistakes, and the page just looks wrong. Two tools find the problem quickly: the browser's DevTools and the free W3C validator.
Learning Objectives
- Spot the effects of common HTML mistakes
- Inspect a page with DevTools
- Check a page with the W3C Markup Validation Service
1. The Browser Fixes, Quietly
Example: three mistakes. Can you spot them before you press Run?
<h2>Shopping list</h3>
<p>Remember to buy <strong>milk and eggs.
<ul>
<li>Bread
<li>Butter</li>
</ul>
<p>That's all.</p><h2>is closed with</h3>.<strong>is never closed, so the bold runs on.- The first
<li>has no closing tag (browsers allow this, but it's inconsistent).
The page still appears, which is exactly why these bugs are easy to miss.
2. DevTools: Inspect
Right-click any part of a page and choose Inspect (or press F12 / ⌘⌥I).
- The Elements panel shows the HTML as the browser understood it. If it differs from what you wrote, that's where your mistake is.
- Hover an element to see its size, padding and margin.
- Double-click to edit text or attributes live.
- The Console panel shows errors from JavaScript and missing files (404s).
3. The W3C Validator
The free validator at validator.w3.org checks your HTML against the standard.
- Choose Validate by Direct Input.
- Paste your HTML.
- Press Check.
It reports problems with line numbers, for example:
Error: End tag h3 seen, but there were open elements. (line 1)
Error: Unclosed element strong. (line 2)Fix the first error first. One mistake often causes several messages after it.
4. A Checklist When Something Looks Wrong
- Are all tags closed, and closed in the right order?
- Are attribute values quoted?
- Are file paths and file-name capitals correct? (Check the Console for 404s.)
- Did you save the file, and refresh the browser?
- Does the validator report any errors?
Common Beginner Mistakes
1. Ignoring validator warnings. Most are quick to fix and prevent odd bugs later.
2. Editing in DevTools and forgetting to copy back. Changes there disappear when you refresh.
3. Fixing errors from the bottom up. The first error often causes the rest.
Practice Questions
- Why doesn't HTML show error messages like other languages?
- How do you open DevTools?
- What does the Elements panel show?
- What is the address of the W3C validator?
- The validator shows ten errors. Which one should you fix first?
Practice Answers
- Browsers are designed to recover from mistakes and display the page anyway.
- Right-click → Inspect, or press F12 (⌘⌥I on a Mac).
- The HTML as the browser has understood (and possibly corrected) it.
- validator.w3.org
- The first one, because it often causes the others.
Key Takeaways
- Broken HTML usually displays anyway, just wrongly.
- DevTools → Elements shows what the browser actually built.
- validator.w3.org finds mistakes by line number.
- Fix the first error first, then check again.