Inspect and validate HTML

HTML Living Standard

A browser can display a page even if its markup contains mistakes. Use DevTools to see the DOM the browser built and a markup checker to find errors in the source.

On this page

How can you see the DOM?

The browser builds a tree called the Document Object Model (DOM) when it reads the file. Run this example or put it inside the body of index.html and open the file. Right-click “Registration is open.” and select Inspect. In Elements or Inspector, look for the paragraph inside <main> and expand <html> to find <head> and <body>.

<main>
  <p>Registration is open.</p>
</main>

Compare the source and the DOM

This example puts a div inside a paragraph on purpose. The parser closes the paragraph before the div. Inspect the preview to see where each element ended up, then edit the source so the paragraph and div are siblings.

<!-- Intentionally invalid nesting -->
<p>Workshop announcement
  <div>Registration opens on Monday.</div>
</p>

What to expect Both lines are visible. In the DOM, the div is outside the paragraph.

Find a duplicate ID with the HTML checker

An ID must be unique within the document. Paste this complete document into the Nu HTML Checker using its text input. Give the second heading a different ID and check again.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Workshop schedule</title>
</head>
<body>
<h1 id="schedule">Workshop schedule</h1>
<h2 id="schedule">Afternoon session</h2>
</body>
</html>

What to expect The browser displays both headings. The checker reports the duplicate schedule ID until you rename it.

Official references