Debugging HTML
Use the browser inspector to find and fix broken HTML.
- Open the browser's element inspector
- Read the DOM to see where elements ended up
- Spot unclosed and misnested tags
- Check alt text and heading order
In plain English
Your browser's developer tools, usually opened with F12, include an inspector that shows the live page. The DOM is the tree of elements the browser built from your HTML, and it is where you check where a tag actually ended up. Most HTML bugs come from unclosed or misnested tags, like an <li> sitting outside its <ul>. You can also use the inspector to check basics such as missing alt text and heading levels that skip a step.
Step by step
- 1Press F12, or right-click an element and choose Inspect, to open the inspector.
- 2Click an element on the page to highlight its place in the DOM tree.
- 3Look for a tag missing its closing tag, or closed in the wrong order.
- 4Check the heading outline and that images have alt text.
- 5Fix the HTML, then reload the page.
<h1>My learning notes</h1>
<section>
<h2>Today</h2>
<ul>
<li>Semantic HTML</li>
<li>Lists and tables</li>
</ul>
</section>
<section>
<h2>Tomorrow</h2>
<p>Practice debugging with the inspector.</p>
</section>Common mistakes
- Forgetting a closing tag, which makes the rest of the page nest in surprising ways.
- Closing tags in the wrong order instead of last-opened-first-closed.
- Reading only the source file instead of the DOM, which is what the browser actually rendered.
- Skipping a heading level just because the next size looks nicer.
Fix the heading outline
This page jumps from an h1 straight to an h3. Fix the levels so the outline steps down one at a time.
<h1>My learning notes</h1>
<h3>Today</h3>
<p>I learned about semantic HTML.</p>What does the DOM show in the inspector?
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Lock in what you just learned.
Mark this lesson complete to save your place and move one step closer to the certificate.