Problem
For decorating a drop down list, one of our web developers used the following html as a placeholder.
<a href="" class="arrow"></a>
Is this an acceptable anchor tag?
It appears as broken in some of our link checker reports because there is no href value.
Asked by matthew
Solution #1
It is valid.
Standard practice is to use href=”#” or href=”javascript:;” instead.
Answered by SLaks
Solution #2
It is valid, as others have stated.
However, each strategy has some drawbacks:
Adding an extra record to the browser history with href=”#” (which is annoying when e.g. back-buttoning).
href=”” causes the page to reload.
href=”javascript:;” doesn’t appear to have any issues (aside from the fact that it looks messy and meaningless) – Anyone know of a good one?
Answered by UpTheCreek
Solution #3
Despite the fact that this question has already been answered (tl;dr: an empty href value is valid), none of the prior answers include a reference to the appropriate specs.
A URI can’t be an empty string. The href attribute, on the other hand, accepts URI references as well as URIs. A URI reference could be an empty string.
RFC 2396 is used in HTML 4.01, as stated in section 4.2. Same-document References (bold emphasis mine):
RFC 2396 has been superseded by RFC 3986 (the current IETF URI standard), which basically says the same thing.
HTML5 employs the W3C’s URL spec, which has been deprecated (valid URL perhaps surrounded by spaces valid URL). Instead, the URL Standard of the WHATWG should be used (see the last section).
WHATWG’s URL Standard is used in HTML 5.1 (valid URL optionally surrounded by spaces valid URL) (see the next section).
WHATWG’s HTML uses the definition of valid URL string from WHATWG’s URL Standard, which says that it can be a relative-URL-with-fragment string, which must at least be a relative-URL string, which can be a path-relative-scheme-less-URL string, which is a path-relative-URL string that doesn’t start with a scheme string followed by:, and its definition says (bold emphasis mine):
Answered by unor
Solution #4
While not including a href may be perfectly legitimate HTML, especially when using a onclick handler, there are a few points to consider: it will not be keyboard-focusable without a tabindex value set. Furthermore, this will be unavailable to screenreader software using Internet Explorer, as IE will report any anchor element without a href attribute as not-focusable through the accessibility interfaces, regardless of whether the tabindex has been set.
As a result, while the following may be entirely true:
<a class="arrow">Link content</a>
It’s far better to include a null-effect href attribute explicitly.
<a href="javascript:void(0);" class="arrow">Link content</a>
If you’re utilizing the class with CSS to render an image, you need also include some text content, such as the title property to provide a textual description of what’s going on, to ensure that all users are fully supported.
<a href="javascript:void(0);" class="arrow" title="Go to linked content">Link content</a>
Answered by Nick
Solution #5
The href attribute can potentially be totally omitted in the current HTML5 draft.
To respond to your query, yes, it is correct.
Answered by halfdan
Post is based on https://stackoverflow.com/questions/5637969/is-an-empty-href-valid