HTML Foundations·Beginner foundations

Debugging HTML

Use the browser inspector to find and fix broken HTML.

Beginner 11 min read Lesson 5 of 480 Challenge included
What you will be able to do
  • 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

  1. 1Press F12, or right-click an element and choose Inspect, to open the inspector.
  2. 2Click an element on the page to highlight its place in the DOM tree.
  3. 3Look for a tag missing its closing tag, or closed in the wrong order.
  4. 4Check the heading outline and that images have alt text.
  5. 5Fix the HTML, then reload the page.
debug.htmlHTML
<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.
Your turn

Fix the heading outline

Easy

This page jumps from an h1 straight to an h3. Fix the levels so the outline steps down one at a time.

HTML · starter
<h1>My learning notes</h1>
<h3>Today</h3>
<p>I learned about semantic HTML.</p>
Check your understanding before moving on.
Knowledge checkQuestion 1

What does the DOM show in the inspector?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 5 of 480 · 0% of course