Skip to content

HTML Unclosed Tag Breaks Layout

Quick summary

You forgot to close a <div> — the browser closes it where it guesses, often swallowing following siblings into the wrong container.

Why this happens

  • Missing closing tag like </div> or </span>

  • Self-closing tags written without the / for void elements that need it in XHTML

  • Tags closed in the wrong order relative to how they were opened

Minimal example

✗ Broken code
<div class="card">
  <p>Hello
</div>
<div class="next">World</div> <!-- p auto-closed, nesting may shift -->
✓ Fixed code
<div class="card">
  <p>Hello</p>
</div>
<div class="next">World</div>

The <p> is never closed, so the browser closes it at the </div>, which can shift following content. Explicitly closing </p> keeps the structure predictable.

How to diagnose

  • Inspect the DOM in DevTools — the nesting will differ from your HTML source

  • Run the HTML through the W3C validator to find mismatched tags

  • Use editor bracket matching to find unclosed tags

How to fix

  • Add the missing closing tag at the correct position

  • Close tags in the reverse order they were opened (LIFO)

  • Use a formatter or Emmet to keep tag pairing automatic

How to prevent

  • Use an HTML linter/validator in your build

  • Let your editor auto-close tags as you type

Related Resources

Related Glossary

Related Lessons

  • HTML

    Learn about HTML structure.

← Back to language