Is <a href="#">link</a> a broken link?
Solution 1
Technically, "#" is a well-defined URL reference that points to the start of the current document, so it is not “broken” in formal sense. It can, however, be regarded as bad for accessibility, and it is also a common symptom of “fake” links, i.e. a
elements that are supposed to link to something external but depend on JavaScript. (In the very old days, <a href="..." onclick="...">
was the only kind of element that supported the onclick
attribute, so people wrote the “dummy” href="#"
attribute, which isn’t really dummy.)
So you can regard this as an incorrect error message, or as a useful warning message that might be a little poorly formulated.
Solution 2
I don't think it is considered as broken link.
Broken link is a link that points to resources doesn't exist (404 HTTP response).
Related videos on Youtube
Jaha Ganiev
Updated on September 18, 2022Comments
-
Jaha Ganiev over 1 year
When using empty URL fragment links, to send a user to the top of the page (e.g.
<a href="#">return to top</a>
), are these links considered broken or invalid? One of my tools is returning them all as broken links. -
msanford over 11 yearsDon't hedge this answer with "In my opinion". It's not a matter of opinion, it's a matter of fact (and you are correct).
-
Zistoloen over 11 years@msanford: You're right, I edited my answer.
-
DisgruntledGoat over 11 yearsDo you have a source for # being well-defined and pointing to the start of the document (i.e. a w3c spec)?
-
Jukka K. Korpela over 11 years@DisgruntledGoat, it’s specified in Internet-standard STD 66, “Uniform Resource Identifier (URI): Generic Syntax”, clause 4.4. Same-Document Reference, available e.g. at tools.ietf.org/html/std66#section-4.4
-
DisgruntledGoat over 11 yearsKudos for providing a source, although I don't see anything that specifies
#
on its own refers to the start of the document. -
Jukka K. Korpela over 11 yearsWell, yes, the standard isn’t too clear about it, but it’s natural to assume that a referenced document is initially positioned at the start. Its predecessor RFC 2396 was more explicit: “4.2. Same-document References. A URI reference that does not contain a URI is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document.”