Is it acceptable to use tags,,, inside links / anchors ()?
Is it acceptable in SEO and semantic question to use tags like <h2>
, <h3>
, <p>
and <div>
inside <a href=""></a>
?
I noticed that to render items on a page people often use a structure similar to this:
<div class="item">
<a href="produto/1">
<figure>
<img src="images/produto-1.jpg" alt="produto 1">
</figure>
<h2>Produto</h2>
<p class="price">R$ 1000</p>
</a>
</div>
I know that the <a>
tag is inline and needs the display: block
to work, but the question really is about SEO and semantics.
2 answers
Is it acceptable to use tags
<h2>
,<h3>
,<p>
,<div>
inside links/anchors (<a></a>
)?
Yes. this is a feature of HTML5 . Other versions did not allow this use.
Already the opposite (put <a>
inside <h1>
, <h2>
, etc.) is the most widely used to date. There are several examples. one of the most notable, in my view, is the documentation of GitHub. Hovering over a title, an image of an anchor appears containing the full link even that anchor.
In the tag specification<a>
in html5 allowed elements the following elements are supported and because they are supported are semantically correct if they do not change the original behavior of <a>
:
> <a>, <abbr>, <address>, <article>,
> <aside>, <audio>, <b>,<bdo>, <bdi>, <blockquote>, <br>, <button>,
> <canvas>, <cite>, <code>, <command>, <data>, <datalist>, <del>,
> <details>, <dfn>, <div>, <dl>, <em>, <embed>, <fieldset>, <figure>,
> <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>,
> <hgroup>, <hr>, <i>, <iframe>, <img>, <input>, <ins>, <kbd>, <keygen>,
> <label>, <main>, <map>, <mark>, <math>, <menu>, <meter>, <nav>,
> <noscript>, <object>, <ol>, <output>, <p>, <pre>, <progress>, <q>,
> <ruby>, <s>, <samp>, <script>, <section>, <select>, <small>, <span>,
> <strong>, <sub>, <sup>, <svg>, <table>, <template>, <textarea>,
> <time>, <ul>, <var>, <video>, <wbr>
Recommended Link SOEN: Is putting a div inside an anchor ever correct?