HTML semantics: Is it a good idea to put links (anchor elements) in headings?

六眼飞鱼酱① 提交于 2020-01-02 08:28:48

问题


Is that wrong to build news list this way:

   <h1><a href="article-1.html">That happened!</a></h1>
   <div class="short">Just like planned</div>

Should I prefer this?

   <h1>That happened!</h1>
   <div class="short">Just like planned</div>
   <div><a href="article-1.html">Read it now</a></div>

or remove header elements?

   <div class="news-header"><a href="article-1.html">That happened!</a></div>
   <div class="short">Just like planned</div>

回答1:


It is syntactically valid to put anchors inside headings.

Your first example: H1 should contain the page heading such as "News". The "list" of news items you should use a sub-heading (H2). On the "details" page you can put the news title in H1.

Your second example: it is valid but not good as far as SEO is concerned. Links that contain text such as "read more", "click here" etc do not tell the search engine what the link is about.

Your third example: it is valid and reasonably good for SEO. But note that the weight of the words used inside heading and bold tags is considered higher by search engines.




回答2:


It's perfectly valid to put a link inside a heading. In fact, Stack overflow even does it on every question page. Do whatever makes most semantic sense for the page.

In HTML5, you can even wrap the heading inside the link, like so:

<a href="article-1.html"><h1>That happened!</h1></a>


来源:https://stackoverflow.com/questions/9782037/html-semantics-is-it-a-good-idea-to-put-links-anchor-elements-in-headings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!