HTML chapters

Chapter 13 of 17

Validation and browser repair

Try this in our HTML Compiler →

The idea

Browsers often repair invalid markup instead of stopping with a console exception. A repaired page can look fine while having the wrong document tree. Inspect the Elements panel and validate a complete document. Common mistakes include duplicate ids, missing alt attributes, and nesting a paragraph inside a paragraph.

Worked example

<!-- Incorrect: a paragraph cannot contain another paragraph. -->
<!-- <p>Outer <p>Inner</p></p> -->
<section>
  <p>First paragraph.</p>
  <p>Second paragraph.</p>
</section>

What to check

The corrected paragraphs are siblings. Browser recovery is not a guarantee that the author's intended structure was preserved.

Practice task

Inspect a page you wrote and check its ids, labels and heading order. Correct one actual structural issue.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on