SEO + AEO on AutopilotFrom the team at Stackmatix
The Growth Library

Check the Links a Browser Keeps After Repairing Nested Anchors

Compare authored links with the browser’s repaired anchor tree. A complete local fixture catches a missing link-label promise even when every intended URL remains in the HTML source.

Use the anchor content model as the boundary

The HTML Standard’s anchor content model disallows an anchor descendant inside another anchor, interactive descendants and descendants carrying tabindex. An outer card link cannot simply wrap every inner action without considering those restrictions.

The HTML parsing rules define recovery from malformed input. Recovery is not permission for a publisher to rely on invalid nesting. It also does not guarantee that every imagined source relationship survives as a relationship in the DOM.

This test uses a genuine browser parser for one controlled case. It is not a custom regular expression pretending to implement the HTML tree builder. The source and expected reader outcome are retained independently from the browser result.

Run the actual parser fixture

Run this Python example in an environment with Playwright and Chromium already installed, adjusting the executable path to that approved local installation if necessary. It uses set_content and performs no navigation to the example host or package installation.

import json
from playwright.sync_api import sync_playwright

bad_html = """<!doctype html><html lang="en"><head>
<base href="https://docs.example/"><title>Local fixture</title>
</head><body><p><a href="/guides/setup">Open setup
<a href="/guides/limits">View limits</a> guide</a></p></body></html>"""
good_html = """<!doctype html><html lang="en"><head>
<base href="https://docs.example/"><title>Local fixture</title>
</head><body><p><a href="/guides/setup">Open setup guide</a>
<a href="/guides/limits">View limits</a></p></body></html>"""
expected = [
    ['https://docs.example/guides/setup', 'Open setup guide'],
    ['https://docs.example/guides/limits', 'View limits'],
]
with sync_playwright() as p:
    browser = p.chromium.launch(headless=True, executable_path='/usr/bin/chromium')
    page = browser.new_page()
    def links(markup):
        page.set_content(markup)
        return page.locator('a').evaluate_all(r"""nodes => nodes.map(a => [
            a.href, a.textContent.replace(/\s+/g, ' ').trim()
        ])""")
    bad = links(bad_html)
    good = links(good_html)
    assert bad != expected
    assert bad[0][1] == 'Open setup'
    assert good == expected
    print(json.dumps({'broken': bad, 'repaired': good}))
    browser.close()
print('parsed destination and text oracle PASS')

The broken output gives the setup link the text “Open setup,” while the trailing word guide remains outside that anchor. The repaired output matches both independently specified destination-and-text pairs. The fixture deliberately fails the broken relationship rather than merely proving that malformed input can still display words.

These results concern the shown markup under the tested browser. Keep the actual browser version and output in the engineering receipt. Do not extend this one fixture into a claim that every malformed card has the same repaired tree.

Separate parser repair from interaction code

After the source structure is corrected, test the real component’s ordinary activation, keyboard activation, new-tab behavior and copied address. The local code above inspects parsed links; it does not certify the application’s event handlers, focus behavior or routing enhancement.

An overlay click handler can still send a visitor to the outer card destination while an inner anchor exposes another address. That is an interaction defect even after the HTML is valid. Review the component under the site’s normal accessibility process instead of adding another event handler to compensate for invalid markup.

Use the anchor promise review for whether the destination fulfills the label. Use the base URL fixture when a valid relative href resolves against the wrong base. Parser boundaries, URL resolution and content relevance are separate findings.

Find the producer shared across cards, related links or CMS blocks. Correct that component and sample representative combinations, especially cards with more than one action. A manual repair in one article will not protect every instance of the same invalid template.

Keep a regression that counts meaning

Retain both the malformed input and the independently expected sibling-link output in a bounded test. Require the destination-and-label pairs, then review actual interactions on the deployed component. A test that only asserts the absence of a nested a element can pass after parser repair even when the source was invalid.

Close on valid authored structure, correct parsed relationships and verified reader interactions. Record discovery and indexing separately. Fixing a parser-repaired card creates a reliable navigation relationship; it does not prove that a search engine will crawl or rank either destination.

Sources

Matt Pru

Co-founder and CEO of Stackmatix. Writing about growth, customer acquisition, and the decisions behind useful marketing. Connect on LinkedIn.

Developed with AI assistance under Matt's editorial direction. Our Editorial Approach