Is href required on links? [duplicate]

2019-01-25 13:23发布

This question already has an answer here:

I'm asking this because I have some links that act like buttons that pull out content trough ajax, so I don't need any href on them.

(I'm asking this from the SEO perspective)

8条回答
唯我独甜
2楼-- · 2019-01-25 13:26

I am assuming that by "links" you simply mean a elements. If that's true then:

No. At least, not in the HTML5 draft specification:

If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant.

From the HTML 4.01 specification:

Authors may also create an A element that specifies no anchors, i.e., that doesn't specify href, name, or id. Values for these attributes may be set at a later time through scripts.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-25 13:32

They're not absolutely required, however you should probably put href="#/" as the href to make it semantically correct. Without an href="" attribute, the anchor is likely to be parsed as a bookmark in the page, especially if the name="" attribute is specified.

查看更多
神经病院院长
4楼-- · 2019-01-25 13:42

Is href required on links?

Yes. Anchors without href attributes are not links.

I'm asking this because I have some links that act like buttons that pull out content trough ajax

If you are doing that, then do it right. Use Unobtrusive JavaScript and pushState.

"Links" that only work if you are using a pointing device and have JS turned on are not good links.

I'm asking this from the SEO perspective

Search engines won't execute your JavaScript, so the pseudo-links (which depend on JS) are just black holes of nothingness as far as they are concerned).

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-25 13:43

If you have links that act like buttons, you should probably have used a <button> element.

查看更多
Ridiculous、
6楼-- · 2019-01-25 13:45

no it's not. But links may render different (underline and color) if the href is not set.

查看更多
做个烂人
7楼-- · 2019-01-25 13:45

I'm not sure, but some time ago I had a problems with "a" without href...the clicks just didn't work. But maybe it was just an old browser.

查看更多
登录 后发表回答