9

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)

Alex
  • 66,732
  • 177
  • 439
  • 641

8 Answers8

27

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.

James Allardice
  • 164,175
  • 21
  • 332
  • 312
  • 1
    This doesn’t match OP’s situation. OP doesn’t want a placeholder link, she wants a button. (Oh, and `a@href` wasn’t required in earlier HTML versions either.) – Mathias Bynens Jan 23 '12 at 11:19
  • 1
    That is true. However, the answer to the question "Is href required on links" is "no". The question over the semantics of how to use such links is a different question altogether. The OPs code would pass a validation test with no `href` attributes. – James Allardice Jan 23 '12 at 11:23
  • 1
    Well, no. Technically, it’s not even a link if it doesn’t contain a `href` attribute. – Mathias Bynens Jan 23 '12 at 11:25
  • 2
    Ok, that's true again. See my assumption at the top of my answer. – James Allardice Jan 23 '12 at 11:26
7

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).

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
6

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

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
2

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

stian.net
  • 3,928
  • 4
  • 25
  • 38
2

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.

Alex Dn
  • 5,465
  • 7
  • 41
  • 79
2

According to the specs it is, and also you'll find browsers implement different default styling (e.g. not changing the cursor to pointer) when you leave out href. The most common approaches to adding dummy hrefs are

href="#" // But the event handler function must return false in order to avoid the default behaviour of jumping to the top of the page

href="javascript:void()" // has the advantage of having no annoying default behaviour
wheresrhys
  • 22,558
  • 19
  • 94
  • 162
1

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.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
0

While it's not required, you should add the href to the anchor tags, because, well without an href they're not really anchor tags.

You can add a '#' to the link and add a onClick='return false;' to prevent the click event. If you're using JQuery, you can add event.preventDefault() to your click handler for your links.

From an SEO perspective, I'd go with using titles for the anchor tags (avoid the -ve text-indent property.)

Sagar Patil
  • 1,938
  • 13
  • 21