Search code examples
htmlhyperlinkhref

What is allowed in a <a> tag


I've looked in W3C specs and couldn't find what is allowed in a <a> tag. I'm asking this because I got a strange behavior while developing a svelte app. In dev mode, the app was able to wrap a <th> inside a <a> like so:

<table>
    <thead>
        <tr>
            <th>Services</th>
            <a href="#details"><th>Details*</th></a>
            <th>Coût</th>
        </tr>
    </thead>
</table>

I got the expected result, a clickable th with a bookmark link to another section in the page.

But when I deployed the production code, svelte didn't wrap the <th> inside a <a>. I also did some tests in codepen.io (enable and siable the Javascript comment to see the difference) and was surprised to learn that a <th> can't be wrapped with an <a> natively but can be forced using Javascript.

Is there a place where I could find a list of the elements allowed within an <a> tag as I always though anything could be wrapped with one.

Thank you!


Solution

  • According to https://html.spec.whatwg.org/multipage/tables.html#the-th-element the th element can only be used inside a tr element.