Article

HTML Doesn't Actually Require Closing Tags (But You Should Use Them Anyway)

Published 2026-09-14

Browsers are far more forgiving than most languages

Try writing invalid syntax in almost any programming language and it simply refuses to run. HTML is different: browsers implement extensive, standardized error-recovery rules specifically so that imperfect, even badly broken HTML still renders as something reasonable, rather than showing an error page to visitors.

Which tags are actually optional by spec

Some HTML tags are officially allowed to omit their closing tag under the HTML5 specification, not just tolerated by lenient browsers: <li>, <p>, <td>, and <tr>, among others, can be legally left unclosed in specific contexts, because the parser can unambiguously infer where they end based on what comes next. This is a genuine, documented part of the standard, not just accidental leniency.

Why relying on this is still a bad practice

Even where it's technically valid, omitting closing tags makes documents significantly harder for humans to read and maintain, and it increases the risk of a browser inferring a different structure than you intended in an edge case, especially once CSS and JavaScript start depending on the exact structure. Every major style guide (Google's, Airbnb's, and others) recommends always closing tags explicitly, treating the spec's leniency as a safety net for malformed real-world content, not a style choice for code you're writing yourself.

Where this leniency actually matters

The real-world value of HTML's error tolerance shows up when a browser has to render content it didn't create itself — a snippet from an old CMS, a chunk of user-submitted content, or a page half-corrupted in transit. Being forgiving here is a deliberate design trade-off that prioritizes always showing something over strict correctness, unlike XML's stricter parsers, which will refuse to render a document at all over a single unclosed tag.

Keep your own HTML clean

Our HTML Formatter reformats markup with clean, consistent, properly nested indentation, making it easy to visually spot a tag that isn't closed where you expect, even though the browser itself wouldn't have complained.

Ready to try it yourself?
Open the HTML Formatter →