How to validate your HTML

Why validation matters

Browsers recover from malformed markup in different ways. Validation catches missing end tags, invalid nesting, duplicate IDs, obsolete attributes, and other mistakes before they become confusing bugs.

Run a standards validator

Use the Nu HTML Checker at validator.w3.org/nu/ by URL, file upload, or pasted source. For local projects, an editor extension or command-line HTML validator can check every save.

Fix the first useful error

  • Start near the earliest reported error because one broken tag can cause many later messages
  • Read errors separately from informational warnings
  • Confirm the document has a doctype, language, charset, title, and correct nesting
  • Search for duplicate id values

Validation is only one check

Valid HTML can still be inaccessible or misleading. Also test keyboard navigation, labels, alt text, heading order, zoom, mobile layouts, links, console errors, and network failures in browser developer tools.

<!doctype html>
<html lang="en">
  <head><meta charset="utf-8"><title>Validated page</title></head>
  <body><main><h1>Validated page</h1></main></body>
</html>