Skip to main content
HTML Validation

End tag “font” violates nesting rules.

About This HTML Issue

The closing </font> tag closes across the boundary of another element that was still open. Tags have to nest cleanly: the element you opened last is the one you close first. When </font> appears while something opened inside it is still open, or it reaches past the element that contains it, the parser can't build a sensible tree and falls back to the adoption agency algorithm to patch things up. Different browsers can patch them differently, so the DOM you get may not match the DOM you wrote, and screen readers lose the real structure of the content.

Examples

Incorrect: </font> crosses a <p> boundary

<p><font color="red">Some text</p>
<p>More text</font></p>

The <font> opens in the first paragraph but closes in the second, so the tags overlap.

Correct: each <font> opens and closes in the same element

<p><font color="red">Some text</font></p>
<p><font color="red">More text</font></p>

Incorrect: closed before a nested <a>

<p><font color="red"><a href="/about">About us</font></a></p>

The <a> opened inside the <font>, so </a> has to come before </font>.

Correct: inner element closed first

<p><font color="red"><a href="/about">About us</a></font></p>

<font> is also obsolete

Fixing the nesting still leaves you with a <font> element, which was dropped from HTML5. Browsers keep parsing it, but the validator flags it on its own too. The simplest fix for both problems is to drop <font> and style the text with CSS. A <span> nests far more predictably:

<style>
  .highlight {
    color: red;
    font-size: 1.2em;
  }
</style>

<p>
  <span class="highlight">This text is styled with CSS.</span>
</p>

Swapping <font> for CSS properties like color, font-size, and font-family clears the nesting violation and the obsolete-element warning at the same time.

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?
🌍 Trusted by teams worldwide

Validate at scale.
Ship accessible websites, faster.

Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.

Scheduled Reports
API Access
Open Source Standards
$7 / 7 days

Pro Trial

Full Pro access. Cancel anytime.

Start Pro Trial →

Join teams across 40+ countries