This question already has an answer here:
-
Is an anchor tag without the href attribute safe?
9 answers
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)
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).
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.
If you have links that act like buttons, you should probably have used a <button>
element.
no it's not. But links may render different (underline and color) if the href is not set.
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.
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
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.
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.)